Sample code for 30+ languages & platforms
Rust

Generate Salt in Hex or Base64 Format

See more Encryption Examples

Demonstrates how to generate a cryptographic salt value and get the result as hex or base64.

Chilkat Rust Downloads

Rust
// In cryptography, a salt is random data that is used as an additional input to a one-way function that "hashes" data, a password or passphrase.

// Let's say we want to generate a 16-byte salt value..
let prng = chilkat::Prng::new();

let salt_hex = prng.gen_random(16, "hex").unwrap_or_default();
println!("16-byte salt as hex: {}", salt_hex);

let salt_base64 = prng.gen_random(16, "base64").unwrap_or_default();
println!("16-byte salt as base64: {}", salt_base64);