encrypt method
Future<SecretBox>
encrypt(
- List<
int> clearText, { - required SecretKey secretKey,
- List<
int> ? nonce, - List<
int> aad = const <int>[], - int keyStreamIndex = 0,
- int? chunkSize,
- Uint8List? possibleBuffer,
override
Encrypts a cleartext.
Parameter keyStreamIndex
allows you to choose offset in the keystream.
For other arguments, see Cipher.encrypt.
Implementation
@override
Future<SecretBox> encrypt(
List<int> clearText, {
required SecretKey secretKey,
List<int>? nonce,
List<int> aad = const <int>[],
int keyStreamIndex = 0,
int? chunkSize,
Uint8List? possibleBuffer,
}) async {
nonce ??= newNonce();
checkParameters(
length: clearText.length,
secretKey: secretKey,
nonceLength: nonce.length,
aadLength: aad.length,
keyStreamIndex: keyStreamIndex,
);
final state = newState();
await state.initialize(
isEncrypting: true,
secretKey: secretKey,
nonce: nonce,
aad: aad,
keyStreamIndex: keyStreamIndex,
);
final cipherText = await state.convert(
clearText,
possibleBuffer: possibleBuffer,
chunkSize: chunkSize,
);
return SecretBox(
cipherText,
nonce: nonce,
mac: state.mac,
);
}