SessionTransportTransformerEncrypt

class SessionTransportTransformerEncrypt(val encryptionKeySpec: SecretKeySpec, val signKeySpec: SecretKeySpec, val ivGenerator: (size: Int) -> ByteArray = { size -> ByteArray(size).apply { SecureRandom().nextBytes(this) } }, val encryptAlgorithm: String = encryptionKeySpec.algorithm, val signAlgorithm: String = signKeySpec.algorithm, backwardCompatibleRead: Boolean = false) : SessionTransportTransformer(source)

A transformer used to sign and encrypt/decrypt session data. This transformer works as follows:

  • encrypts/decrypts data using encryptAlgorithm and encryptionKeySpec

  • includes an authenticated MAC (Message Authentication Code) hash with signAlgorithm and signKeySpec

  • includes an IV (Initialization Vector) that is generated by an ivGenerator by default secure random bytes

By default, it uses AES for encryption and HmacSHA256 for authentication.

You have to provide keys of compatible sizes: 16, 24 and 32 for AES encryption. For HmacSHA256 it is recommended a key of 32 bytes.

Report a problem

See also

Sessions

Constructors

Link copied to clipboard
constructor(encryptionKeySpec: SecretKeySpec, signKeySpec: SecretKeySpec, ivGenerator: (size: Int) -> ByteArray = { size -> ByteArray(size).apply { SecureRandom().nextBytes(this) } }, encryptAlgorithm: String = encryptionKeySpec.algorithm, signAlgorithm: String = signKeySpec.algorithm, backwardCompatibleRead: Boolean = false)
constructor(encryptionKey: ByteArray, signKey: ByteArray, ivGenerator: (size: Int) -> ByteArray = { size -> ByteArray(size).apply { SecureRandom().nextBytes(this) } }, encryptAlgorithm: String = "AES", signAlgorithm: String = "HmacSHA256", backwardCompatibleRead: Boolean = false)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

is an encryption algorithm name

Link copied to clipboard

A size of the key used to encrypt session data.

Link copied to clipboard

is a secret key that is used for encryption

Link copied to clipboard
val ivGenerator: (size: Int) -> ByteArray

is a function that generates input vectors

Link copied to clipboard

is a signing algorithm name

Link copied to clipboard

is a secret key that is used for signing

Functions

Link copied to clipboard
open override fun transformRead(transportValue: String): String?

Untransforms a transportValue that represents a transformed session.

Link copied to clipboard
open override fun transformWrite(transportValue: String): String

Transforms a transportValue that represents session data.