fernetDecrypt method

String fernetDecrypt(
  1. String secretKey,
  2. Encrypted encryptedValue
)

Decrypts the given encryptedValue with the provided secretKey using the Fernet decryption algorithm.

Returns the decrypted value as a string.

Implementation

String fernetDecrypt(String secretKey, Encrypted encryptedValue) {
  final key = Key.fromUtf8(secretKey);
  final b64key = Key.fromUtf8(base64Url.encode(key.bytes).substring(0, 32));
  final fernet = Fernet(b64key);
  final encrypter = Encrypter(fernet);

  final decrypted = encrypter.decrypt(encryptedValue);

  return decrypted;
}