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, SALT_LENGTH);
final iv = cText.sublist(SALT_LENGTH, SALT_LENGTH + IV_LENGTH);
final mac = cText.sublist(cText.length - TAG_LENGTH);
final text =
cText.sublist(SALT_LENGTH + IV_LENGTH, cText.length - TAG_LENGTH);
final algorithm = AesGcm.with256bits();
final key = await deriveKey(password, salt);
final secretBox = new SecretBox(text, nonce: iv, mac: new Mac(mac));
final cleartext = await algorithm.decrypt(
secretBox,
secretKey: key,
);
return utf8.decode(cleartext);
}