deriveNewKeyFromString function

Future<DerivedKey> deriveNewKeyFromString(
  1. String passphrase,
  2. DerivationStrategy strategy
)

Provided a user-entered passphrase and a key derivation strategy, derive a data encryption key with randomly generated derivation artefacts. The key and artefacts can be serialized for transfer over the wire and storage.

Implementation

Future<DerivedKey> deriveNewKeyFromString(
    String passphrase, DerivationStrategy strategy) async {
  final DerivationArtefacts artefacts =
      DerivationArtefacts.generate(strategy: strategy);
  final DerivationService service = strategy.toService();

  final keyBytes =
      await service.deriveKey(artefacts: artefacts, passphrase: passphrase);
  return DerivedKey._(
      key: DataEncryptionKey.loadFromBytes(keyBytes),
      derivationArtefacts: artefacts);
}