cryptography
cryptography copied to clipboard
Make HKDF nonce optional
In version 2.0.0-nullsafety.2
of cryptography
, the Dart implementation of HKDF requires a non-empty nonce which differs from the web crypto implementation and past versions of the package.
Providing Uint8List(0)
as a nonce like below throws an error.
final keyByteLength = 256 ~/ 8;
final kdf = Hkdf(hmac: Hmac(Sha256()), outputLength: keyByteLength);
final derivedKey = await kdf.deriveKey(
secretKey: secretKey,
info: utf8.encode('some info'),
nonce: Uint8List(0),
);
My use case for this is to deterministically generate a key from a user-provided key without any additional inputs.