Sample code for 30+ languages & platforms
Lianja

PBKDF2 Key Derivation

Demonstrates AES secret key derivation from a password using PBDKF2.

Chilkat Lianja Downloads

Lianja
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loCrypt = createobject("CkCrypt2")

lcPassword = "correcthorsebatterystaple"

// Derive from the utf-8 byte representation of the password.
lcCharset = "utf-8"

lcHashAlg = "sha256"

loCrypt.EncodingMode = "hex"
lcSaltHex = loCrypt.GenRandomBytesENC(16)

lnIterationCount = 310000

// Derive a 256-bit key from the password.
lnOutputBitLen = 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.)
lcEnc = "hex"

lcHexKey = loCrypt.Pbkdf2(lcPassword,lcCharset,lcHashAlg,lcSaltHex,lnIterationCount,lnOutputBitLen,lcEnc)

? lcHexKey

// Sample output:
// 597734C894FF89CFD3B93D925462C24E97724BCB118F6FC919007F5ABC27E768


release loCrypt