Fernet constructor
Fernet(
- dynamic key
key
is URL-safe base64-encoded and it has to
be 32-bytes long before base64-encoding.
This must be kept secret.
Anyone with this key
is able to create and read messages.
Implementation
Fernet(dynamic key) {
if (key is! Uint8List && key is! String) {
throw ArgumentError('key must be Uint8List or String');
}
try {
final String keyStr = key is String ? key : utf8.decode(key);
final Uint8List keyDecoded = base64Url.decode(keyStr);
if (keyDecoded.length != 32) {
throw FormatException();
}
_signingKey = keyDecoded.sublist(0, 16);
_encryptionKey = keyDecoded.sublist(16, 32);
} on FormatException {
throw ArgumentError(
'Fernet key must be 32 url-safe base64-encoded bytes.',
);
}
}