argon2 library

Argon2id cryptography wrappers and parametrization.

https://datatracker.ietf.org/doc/html/rfc9106

Turns a password and a salt into key material, made deliberately slow and memory hungry so guessing passwords is expensive. For stretching a secret that is already random, see the hkdf library instead.

import 'dart:convert';

import 'package:darkbio_crypto/argon2.dart' as argon2;
import 'package:darkbio_crypto/rand.dart' as rand;

void example() {
  // Store the salt and the costs to derive the same key again later
  final salt = rand.bytes(16);
  final key = argon2.key(
    password: utf8.encode('password'),
    salt: salt,
    time: 3,
    memory: 64 * 1024,
    threads: 4,
  );
  assert(key.length == 32);
}

Functions

key({required Uint8List password, required Uint8List salt, int time = 3, int memory = 65536, int threads = 4, int length = 32}) → Uint8List
Derives a key from the password, salt and cost parameters using Argon2id, returning length bytes that can be used as a cryptographic key.