aesGcmEncrypt function
AES-256-GCM encrypt. Output layout: ciphertext + 16-byte tag.
Implementation
Uint8List? aesGcmEncrypt(Uint8List key, Uint8List plaintext) {
if (key.length != _aesKeySize) {
return null;
}
final nonce = _secureNonce(_nonceSize);
final cipher = GCMBlockCipher(AESEngine())
..init(
true,
AEADParameters(KeyParameter(key), _macBits, nonce, Uint8List(0)),
);
final encrypted = cipher.process(plaintext);
final output = Uint8List(_nonceSize + encrypted.length);
output.setRange(0, _nonceSize, nonce);
output.setRange(_nonceSize, output.length, encrypted);
return output;
}