Sample code for 30+ languages & platforms
DataFlex

Example: Crypt2.DecryptStringENC method

Demonstrates how to call the DecryptStringENC method.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoCrypt
    String sEncodedEncrypted
    String sOriginalText

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

    Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt
    If (Not(IsComObjectCreated(hoCrypt))) Begin
        Send CreateComObject of hoCrypt
    End

    Set ComCryptAlgorithm Of hoCrypt To "aes"
    Set ComCipherMode Of hoCrypt To "cbc"
    Set ComKeyLength Of hoCrypt To 128
    Send ComSetEncodedKey To hoCrypt "000102030405060708090A0B0C0D0E0F" "hex"
    Send ComSetEncodedIV To hoCrypt "000102030405060708090A0B0C0D0E0F" "hex"
    Set ComEncodingMode Of hoCrypt To "base64"

    // Return the base64 encoded encrypted bytes
    Get ComEncryptStringENC Of hoCrypt "Hello World!" To sEncodedEncrypted
    Showln "Encrypted: " sEncodedEncrypted

    // Output:
    // Encrypted: qiq+IFhcjTkEIkZyf31V/g==

    // Decrypt
    Get ComDecryptStringENC Of hoCrypt sEncodedEncrypted To sOriginalText

    Showln "Decrypted: " sOriginalText

    // Output:
    // Decrypted: Hello World!


End_Procedure