encrypt method
Encrypts data to be used in Secure Messaging.
data must be padded (if needed) before calling this function.
ssc is used as IV for encryption.
Implementation
@override
Uint8List encrypt(Uint8List data, {SSC? ssc}) {
_log.debug(
"encrypt: data size: ${data.length}, ssc: ${ssc?.toBytes().hex()}");
_log.sdVerbose("encrypt: data: ${data.hex()}, KSenc: ${KSenc.hex()}");
if (ssc == null)
throw Exception("PACE_SMCipher_AES.encrypt: SSC should not be null");
//IV = E(KSenc, SCC)
_log.sdDebug(
"Encrypting IV with KSenc: ${KSenc.hex()}, ssc: ${ssc.toBytes().hex()}");
Uint8List iv = cipher.encrypt(
data: ssc.toBytes(), key: KSenc, mode: BLOCK_CIPHER_MODE.ECB);
_log.sdVerbose("Encrypted IV: ${iv.hex()}");
_log.sdDebug("Encrypting data with KSenc: ${KSenc.hex()}, iv: ${iv.hex()}");
Uint8List encrypted = cipher.encrypt(data: data, key: KSenc, iv: iv);
_log.sdVerbose("Encrypted data: ${encrypted.hex()}");
return encrypted;
}