deriveKeyFromPasswordBytes method
Derives a key from password bytes and salt.
passwordBytes
should be UTF-8 encoded password bytes.
salt
is the cryptographic salt.
userIdBytes
is optional - when provided, will be prepended as
"userId:password" per RFC 5054 specification.
Implementation
@override
Future<Uint8List> deriveKeyFromPasswordBytes({
required Uint8List passwordBytes,
required Uint8List salt,
Uint8List? userIdBytes,
}) async {
// I | ':' | p if userId is provided, otherwise just p.
final inputToHash = concatenateUserIdAndPassword(userIdBytes, passwordBytes);
// First hash: H(I | ':' | p)
final hashedPassword = await hashFunction.hash(inputToHash);
// RFC 5054: x = H(s, H(I | ':' | p))
final combined = Uint8List.fromList([
...salt,
...hashedPassword,
]);
final finalHash = await hashFunction.hash(combined);
return finalHash;
}