decryptData method
Decrypts iv(12) | ciphertext | tag(16); throws on auth failure.
Implementation
@override
Future<Uint8List> decryptData(Uint8List key, Uint8List data) async {
if (data.length < 28) {
throw const FormatException('Data too short for AES-GCM');
}
final sk = await _algo.newSecretKeyFromBytes(key);
final nonce = data.sublist(0, 12);
final ct = data.sublist(12, data.length - 16);
final mac = data.sublist(data.length - 16);
final clear = await _algo.decrypt(
cg.SecretBox(ct, nonce: nonce, mac: cg.Mac(mac)),
secretKey: sk,
);
return Uint8List.fromList(clear);
}