SessionTransportTransformerEncrypt

class SessionTransportTransformerEncrypt : 
    SessionTransportTransformer

Session transformer that encrypts/decrypts the input.

Where the input is either a session contents or a previous transformation.

It encrypts/decrypts the input with an encryptAlgorithm and an encryptionKeySpec and includes an authenticated MAC (Message Authentication Code) hash with signAlgorithm and a signKeySpec and 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 authenticating.

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.

Constructors

<init>

SessionTransportTransformerEncrypt(
    encryptionKey: ByteArray,
    signKey: ByteArray,
    ivGenerator: (size: Int) -> ByteArray = { size -> SecureRandom().generateSeed(size) },
    encryptAlgorithm: String = "AES",
    signAlgorithm: String = "HmacSHA256")
SessionTransportTransformerEncrypt(
    encryptionKeySpec: SecretKeySpec,
    signKeySpec: SecretKeySpec,
    ivGenerator: (size: Int) -> ByteArray = { size -> SecureRandom().generateSeed(size) },
    encryptAlgorithm: String = encryptionKeySpec.algorithm,
    signAlgorithm: String = signKeySpec.algorithm)

Session transformer that encrypts/decrypts the input.

Properties

encryptAlgorithm

val encryptAlgorithm: String

is an encryption algorithm name

encryptionKeySize

val encryptionKeySize: Int

Encryption key size in bytes

encryptionKeySpec

val encryptionKeySpec: SecretKeySpec

is a secret key that is used for encryption

ivGenerator

val ivGenerator: (size: Int) -> ByteArray

is a function that generates input vectors

signAlgorithm

val signAlgorithm: String

is a signing algorithm name

signKeySpec

val signKeySpec: SecretKeySpec

is a secret key that is used for signing

Functions

transformRead

fun transformRead(transportValue: String): String?

Un-apply a transformation for transportValue representing a transformed session. Returns null if it fails.

transformWrite

fun transformWrite(transportValue: String): String

Apply a transformation for transportValue representing a session.