Sample code for 30+ languages & platforms
PureBasic

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 PureBasic Downloads

PureBasic
IncludeFile "CkPrng.pb"

Procedure ChilkatExample()

    ; 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..
    prng.i = CkPrng::ckCreate()
    If prng.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    saltHex.s = CkPrng::ckGenRandom(prng,16,"hex")
    Debug "16-byte salt as hex: " + saltHex

    saltBase64.s = CkPrng::ckGenRandom(prng,16,"base64")
    Debug "16-byte salt as base64: " + saltBase64


    CkPrng::ckDispose(prng)


    ProcedureReturn
EndProcedure