pbkdfDeriveDigest function
This function derives a key from a mnemonic passphrase and a salt using the PBKDF2 algorithm with SHA-512. It returns a Uint8List representing the derived key.
Implementation
Uint8List pbkdfDeriveDigest(String mnemonic, String salt) {
/// Convert the salt string into a Uint8List of bytes.
final toBytesSalt = Uint8List.fromList(utf8.encode(salt));
/// Create a PBKDF2 key derivator with an HMAC-SHA-512 pseudorandom function and a 128-bit block size.
final derive = PBKDF2KeyDerivator(HMac(SHA512Digest(), 128));
/// Reset the derivator to its initial state.
derive.reset();
/// Initialize the derivator with the salt, iteration count (2048), and desired key length (64 bytes).
derive.init(Pbkdf2Parameters(toBytesSalt, 2048, 64));
/// Convert the mnemonic passphrase string into a Uint8List of bytes and derive the key.
return derive.process(Uint8List.fromList(mnemonic.codeUnits));
}