Sample code for 30+ languages & platforms
Tcl

PBKDF2 Key Derivation

Demonstrates AES secret key derivation from a password using PBDKF2.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

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

set crypt [new_CkCrypt2]

set password "correcthorsebatterystaple"

# Derive from the utf-8 byte representation of the password.
set charset "utf-8"

set hashAlg "sha256"

CkCrypt2_put_EncodingMode $crypt "hex"
set saltHex [CkCrypt2_genRandomBytesENC $crypt 16]

set iterationCount 310000

# Derive a 256-bit key from the password.
set 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.)
set enc "hex"

set hexKey [CkCrypt2_pbkdf2 $crypt $password $charset $hashAlg $saltHex $iterationCount $outputBitLen $enc]

puts "$hexKey"

# Sample output:
# 597734C894FF89CFD3B93D925462C24E97724BCB118F6FC919007F5ABC27E768

delete_CkCrypt2 $crypt