encrypt method
Encrypts (with iv) and return in base 64.
IV should be base-64 encoded. Input should be a valid UTF-8 string.
aad
is optional, ChaCha20-Poly1305 is secure without it.
Implementation
String encrypt(
{required String inp,
required String iv,
String? aad,
int tagLength = 128}) {
var key = base64Decode(_key32);
var ivLocal = base64Decode(iv);
var localInput = utf8.encode(inp);
var aadLocal = aad != null ? base64Decode(aad) : Uint8List(0);
var cipherparams =
AEADParameters(KeyParameter(key), tagLength, ivLocal, aadLocal);
var cipher = ChaCha20Poly1305(ChaCha7539Engine(), Poly1305());
cipher.init(true, cipherparams);
var inter = cipher.process(localInput as Uint8List);
return base64.encode(inter);
}