Node.js
Node.js
PBKDF2 Key Derivation
Demonstrates AES secret key derivation from a password using PBDKF2.Chilkat Node.js Downloads
NODEJS_PRELUDE
function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var crypt = new chilkat.Crypt2();
var password = "correcthorsebatterystaple";
// Derive from the utf-8 byte representation of the password.
var charset = "utf-8";
var hashAlg = "sha256";
crypt.EncodingMode = "hex";
var saltHex = crypt.GenRandomBytesENC(16);
var iterationCount = 310000;
// Derive a 256-bit key from the password.
var outputBitLen = 256;
// The derived key is returned as a hex or base64 encoded string.
// (Note: The salt argument must be a string that also uses
// the same encoding.)
var enc = "hex";
var hexKey = crypt.Pbkdf2(password,charset,hashAlg,saltHex,iterationCount,outputBitLen,enc);
console.log(hexKey);
// Sample output:
// 597734C894FF89CFD3B93D925462C24E97724BCB118F6FC919007F5ABC27E768
}
chilkatExample();