encryptData method

  1. @override
Future<Uint8List> encryptData(
  1. Uint8List key,
  2. Uint8List data
)
override

Returns iv(12) | ciphertext | tag(16).

Implementation

@override
Future<Uint8List> encryptData(Uint8List key, Uint8List data) async {
  final sk = await _algo.newSecretKeyFromBytes(key);
  final nonce = _algo.newNonce(); // 12 bytes
  final box = await _algo.encrypt(data, secretKey: sk, nonce: nonce);
  return Uint8List.fromList([...nonce, ...box.cipherText, ...box.mac.bytes]);
}