Rust
Rust
Password_Digest = Base64 (SHA-1 ( nonce + created + SHA-1 (password) ) )
See more Encryption Examples
Demonstrates how to compute:Password_Digest = Base64 (SHA-1 ( nonce + created + SHA-1 (password)))
Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let password = "secret".to_string();
let crypt = chilkat::Crypt2::new();
crypt.set_hash_algorithm("SHA-1");
crypt.set_encoding_mode("base64");
// Generate a 16-byte random nonce
let prng = chilkat::Prng::new();
let bd = chilkat::BinData::new();
let _ = prng.gen_random_bd(16, &bd);
// Get the current date/time in a string with this format: 2010-06-08T07:26:50Z
let dt = chilkat::DateTime::new();
let _ = dt.set_from_current_system_time();
let created = dt.get_as_timestamp(false).unwrap_or_default();
let _ = bd.append_string(&created, "utf-8");
// This example wishes to calculate a password digest like this:
// Password_Digest = Base64 ( SHA-1 ( nonce + created + SHA-1(password) ) )
// First SHA-1 digest the password...
let password_sha1 = crypt.hash_string_enc(&password).unwrap_or_default();
// Append the 20 binary bytes of the SHA1 hash to bd, which already contains the nonce and created date/time.
let _ = bd.append_encoded(&password_sha1, "base64");
let password_digest = crypt.hash_bd_enc(&bd).unwrap_or_default();
println!("Base64 password digest = {}", password_digest);