Sample code for 30+ languages & platforms
JavaScript

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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
// 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..
var prng = new CkPrng();

var saltHex = prng.GenRandom(16,"hex");
console.log("16-byte salt as hex: " + saltHex);

var saltBase64 = prng.GenRandom(16,"base64");
console.log("16-byte salt as base64: " + saltBase64);