decrypt static method
Decrypts passed ciphertext
with key generated based on password
argument
Implementation
static Future<String> decrypt(String cipherText, String password) async {
final cText = hex.decode(cipherText);
final salt = cText.sublist(0, _saltLength);
final iv = cText.sublist(_saltLength, _saltLength + _ivLength);
final mac = cText.sublist(cText.length - _tagLength);
final text =
cText.sublist(_saltLength + _ivLength, cText.length - _tagLength);
final algorithm = AesGcm.with256bits();
final key = await deriveKey(password, salt);
final secretBox = SecretBox(text, nonce: iv, mac: Mac(mac));
final cleartext = await algorithm.decrypt(
secretBox,
secretKey: key,
);
return utf8.decode(cleartext);
}