rscrypto 0.6.0

Pure Rust Cryptography: RSA, Ed25519, X25519, SHA-2/3, BLAKE2/3, AES-GCM/GCM-SIV, X/ChaCha20-Poly1305, Argon2, HMAC/HKDF, CRC. no_std, WASM, hardware acceleration.
Documentation
//! Password hashing with Argon2id and scrypt.
//!
//! Run with:
//!
//! ```text
//! cargo run --example password_hashing --features password-hashing,getrandom
//! ```

use rscrypto::{Argon2Params, Argon2id, Scrypt, ScryptParams};

fn main() -> Result<(), Box<dyn core::error::Error>> {
  let password = b"correct horse battery staple";

  let argon2 = Argon2Params::new().build()?;
  let argon2_phc = Argon2id::hash_string(&argon2, password)?;
  assert!(Argon2id::verify_string(password, &argon2_phc).is_ok());
  assert!(Argon2id::verify_string(b"wrong password", &argon2_phc).is_err());

  let scrypt = ScryptParams::new().build()?;
  let scrypt_phc = Scrypt::hash_string(&scrypt, password)?;
  assert!(Scrypt::verify_string(password, &scrypt_phc).is_ok());
  assert!(Scrypt::verify_string(b"wrong password", &scrypt_phc).is_err());

  println!("{argon2_phc}");
  println!("{scrypt_phc}");

  Ok(())
}