Pbkdf2SecretKey class abstract

PBKDF2 secret key (or password) for key derivation.

An Pbkdf2SecretKey instance holds a secret key for key derivation using PKCS#5 password-based key derivation function version 2 as specified in RFC 8018 using HMAC as pseudo-random function. The HMAC will used the Hash algorithm given in deriveBits.

A Pbkdf2SecretKey can be imported using importRawKey.

Example

import 'dart:convert' show utf8, base64;
import 'package:webcrypto/webcrypto.dart';

// Provide a password to be used for key derivation
final key = await Pbkdf2SecretKey.importRawKey(utf8.decode(
  'my-password-in-plain-text',
));

// Derive a key from password
final derivedKey = await Pbkdf2SecretKey.deriveBits(
  256, // number of bits to derive.
  Hash.sha256,
  utf8.decode('unique salt'),
  100000,
);

// Print the derived key, this could also be used as basis for other new
// symmetric cryptographic keys.
print(base64.encode(derivedKey));
Annotations
  • @sealed

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

deriveBits(int length, Hash hash, List<int> salt, int iterations) Future<Uint8List>
Derive key from salt and password specified as keyData in importRawKey.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

importRawKey(List<int> keyData) Future<Pbkdf2SecretKey>
Import Pbkdf2SecretKey from raw keyData.