Skip to main content

argon2_hash

Function argon2_hash 

Source
pub fn argon2_hash(password: &[u8]) -> Result<String>
Available on (crate features kdf-hkdf or kdf-argon2) and crate feature kdf-argon2 only.
Expand description

Hash password with Argon2id using the default parameter set and a fresh random salt. Returns the PHC-encoded hash string.

The salt is generated via mod_rand::tier3::fill_bytes (OS CSPRNG) and embedded in the returned string, so callers do not need to manage salt storage separately.

§Errors

Returns Error::RandomFailure if the OS RNG cannot produce a salt, or Error::Kdf if the Argon2 implementation rejects the (default) parameters or fails to hash.

§Example

use crypt_io::kdf;
let phc = kdf::argon2_hash(b"correct horse battery staple")?;
assert!(phc.starts_with("$argon2id$"));