encrypt static method
Encrypts passed cleartext
with key generated based on password
argument
Implementation
static Future<String> encrypt(String cleartext, String password) async {
final salt = randomBytes(_saltLength);
final iv = randomBytes(_ivLength);
final key = await deriveKey(password, salt);
final algorithm = AesGcm.with256bits();
final secretBox = await algorithm.encrypt(
utf8.encode(cleartext),
secretKey: key,
nonce: iv,
);
final List<int> result =
salt + secretBox.nonce + secretBox.cipherText + secretBox.mac.bytes;
return hex.encode(result);
}