pbkdf2 function

HashDigest pbkdf2(
  1. List<int> password,
  2. List<int> salt, [
  3. int? iterations,
  4. int? keyLength,
])

This is an implementation of Password Based Key Derivation Algorithm, PBKDF2 derived from RFC-8081, which internally uses sha256 hash function for key derivation.

Parameters:

  • password is the raw password to be encoded.
  • salt should be at least 8 bytes long. 16 bytes is recommended.
  • iterations is the number of iterations. Default: 50000
  • keyLength is the length of the generated key. Default: 32

The strength of the generated key depends on the number of iterations. The idea is to prevent a brute force attack on the original password by making the key derivation time long.

Implementation

@pragma('vm:prefer-inline')
HashDigest pbkdf2(
  List<int> password,
  List<int> salt, [
  int? iterations,
  int? keyLength,
]) =>
    hmac_sha256
        .pbkdf2(
          salt,
          keyLength: keyLength,
          iterations: iterations,
        )
        .convert(password);