encryptBytes function
Encrypt the given bytes
to the given outputFile
, and return the
encryption key.
Implementation
String encryptBytes({
required final List<int> bytes,
required final File outputFile,
final String? encryptionKey,
}) {
final actualEncryptionKey = encryptionKey ?? generateEncryptionKey();
final key = Key.fromBase64(actualEncryptionKey);
final iv = IV.fromLength(16);
final encrypter = Encrypter(AES(key));
final data = encrypter
.encryptBytes(
bytes,
iv: iv,
)
.bytes;
outputFile.writeAsBytesSync(data);
return actualEncryptionKey;
}