io.altoo.serialization.kryo.scala.DefaultKeyProvider.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scala-kryo-serialization_2.12 Show documentation
Show all versions of scala-kryo-serialization_2.12 Show documentation
pekko-serialization implementation using kryo - core implementation
The newest version!
package io.altoo.serialization.kryo.scala
import com.typesafe.config.Config
import javax.crypto.SecretKeyFactory
import javax.crypto.spec.PBEKeySpec
/**
* Default encryption key provider that can be extended to provide encryption key differently.
*/
class DefaultKeyProvider {
/**
* @param config The config scope of the serializer
*/
def aesKey(config: Config): Array[Byte] = {
val password = config.getString("encryption.aes.password")
val salt = config.getString("encryption.aes.salt")
deriveKey(password, salt)
}
protected final def deriveKey(password: String, salt: String): Array[Byte] = {
val factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256")
val spec = new PBEKeySpec(password.toCharArray, salt.getBytes("UTF-8"), 65536, 256)
factory.generateSecret(spec).getEncoded
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy