deriveKeyFromPasswordBytes method

  1. @override
Future<Uint8List> deriveKeyFromPasswordBytes({
  1. required Uint8List passwordBytes,
  2. required Uint8List salt,
  3. Uint8List? userIdBytes,
})
override

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 {
  final stopwatch = onDeriveComplete != null ? (Stopwatch()..start()) : null;

  // I | ':' | p
  final input = concatenateUserIdAndPassword(userIdBytes, passwordBytes);
  final secretKey = await argon2.deriveKey(
    secretKey: SecretKey(input),
    nonce: salt,
  );
  final bytes = await secretKey.extractBytes();

  if (stopwatch != null) {
    stopwatch.stop();
    onDeriveComplete!(stopwatch.elapsedMilliseconds);
  }

  return Uint8List.fromList(bytes);
}