Sample code for 30+ languages & platforms
PureBasic

Example: Crypt2.HashStringENC method

Demonstrates how to call the HashStringENC method.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkCrypt2.pb"

Procedure ChilkatExample()

    crypt.i = CkCrypt2::ckCreate()
    If crypt.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    s.s = "får"

    ; The string "får" in utf-8 is composed of these bytes: 0x66 0xC3 0xA5 0x72
    CkCrypt2::setCkCharset(crypt, "utf-8")

    CkCrypt2::setCkEncodingMode(crypt, "hex_lower")
    CkCrypt2::setCkHashAlgorithm(crypt, "sha256")

    ; Get the hex string for the sha-256 hash of the utf-8 byte representation of the string
    hashStr.s = CkCrypt2::ckHashStringENC(crypt,s)

    Debug hashStr

    ; Output:
    ; cb8f773dd592337ed7f928012a60f48e1efb357beeda124a54461410e216fece


    CkCrypt2::ckDispose(crypt)


    ProcedureReturn
EndProcedure