Sample code for 30+ languages & platforms
Xbase++

Encrypt / Decrypt a File and Verify it has not Changed

See more Encryption Examples

Demonstrates how to encrypt and decrypt a file, and verify it has not changed.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oCrypt
LOCAL cIvHex
LOCAL cKeyHex
LOCAL cDataFile
LOCAL cOutFile
LOCAL cOutFile2
LOCAL oFac
LOCAL nBEqual

nSuccess := 0

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

oCrypt := CreateObject("Chilkat.Crypt2")

oCrypt:CryptAlgorithm := "aes"
oCrypt:CipherMode := "cbc"
oCrypt:KeyLength := 128
oCrypt:PaddingScheme := 0

cIvHex := "000102030405060708090A0B0C0D0E0F"
oCrypt:SetEncodedIV(cIvHex, "hex")

cKeyHex := "00010203040506071011121314151617"
oCrypt:SetEncodedKey(cKeyHex, "hex")

cDataFile := "qa_data/zips/HBIQ040615300005.ZIP"
cOutFile := "qa_output/HBIQ040615300005.enc"
cOutFile2 := "qa_output/HBIQ040615300005.ZIP"

nSuccess := oCrypt:CkEncryptFile(cDataFile, cOutFile)
nSuccess := oCrypt:CkDecryptFile(cOutFile, cOutFile2)

oFac := CreateObject("Chilkat.FileAccess")
nBEqual := oFac:FileContentsEqual(cDataFile, cOutFile2)
IF (nBEqual != 1)
    ? "Decrypted file not equal to the original."
ELSE
    ? "Success."
ENDIF

oCrypt:destroy()
oFac:destroy()