decrypt method
Decrypts (with iv) and return in base 64.
IV should be base-64 encoded. encrypted
should be the result of
ChaCha20-Poly1305 encryption, encoded in base-64. encrypt takes care of
this for you.
aad
is optional, ChaCha20-Poly1305 is secure without it.
Implementation
String decrypt(
{required String enc,
required String iv,
String? aad,
int tagLength = 128}) {
var key = base64Decode(_key32);
var ivLocal = base64Decode(iv);
var localInput = base64Decode(enc);
var aadLocal = aad != null ? base64Decode(aad) : Uint8List(0);
var cipherparams =
AEADParameters(KeyParameter(key), tagLength, ivLocal, aadLocal);
var cipher = ChaCha20Poly1305(ChaCha7539Engine(), Poly1305());
cipher.init(false, cipherparams);
var inter = cipher.process(localInput);
return utf8.decode(inter);
}