createHashFromString method

Future<String> createHashFromString({
  1. required String secret,
  2. @protected Uint8List? salt,
})

Create the hash for the given secret (String).

Applies a random salt, which must be stored with the hash to validate it later. If salt is provided, it will be used instead of generating a random one.

Returns a PHC-formatted string: $argon2id$v=19$m={memory},t={iterations},p={lanes}${base64Salt}$${base64Hash}

Implementation

Future<String> createHashFromString({
  required final String secret,
  @protected Uint8List? salt,
}) async {
  salt ??= generateRandomBytes(_hashSaltLength);
  final pepper = _hashPeppers.first;
  final secretBytes = utf8.encode(secret);

  final result = await _createHash(
    secret: secretBytes,
    salt: salt,
    pepper: pepper,
  );

  return result.toPhcHashString();
}