PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Crypt
string ls_IvHex
string ls_KeyHex
string ls_DataFile
string ls_OutFile
string ls_OutFile2
oleobject loo_Fac
integer li_BEqual
li_Success = 0
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")
if li_rc < 0 then
destroy loo_Crypt
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Crypt.CryptAlgorithm = "aes"
loo_Crypt.CipherMode = "cbc"
loo_Crypt.KeyLength = 128
loo_Crypt.PaddingScheme = 0
ls_IvHex = "000102030405060708090A0B0C0D0E0F"
loo_Crypt.SetEncodedIV(ls_IvHex,"hex")
ls_KeyHex = "00010203040506071011121314151617"
loo_Crypt.SetEncodedKey(ls_KeyHex,"hex")
ls_DataFile = "qa_data/zips/HBIQ040615300005.ZIP"
ls_OutFile = "qa_output/HBIQ040615300005.enc"
ls_OutFile2 = "qa_output/HBIQ040615300005.ZIP"
li_Success = loo_Crypt.CkEncryptFile(ls_DataFile,ls_OutFile)
li_Success = loo_Crypt.CkDecryptFile(ls_OutFile,ls_OutFile2)
loo_Fac = create oleobject
li_rc = loo_Fac.ConnectToNewObject("Chilkat.FileAccess")
li_BEqual = loo_Fac.FileContentsEqual(ls_DataFile,ls_OutFile2)
if li_BEqual <> 1 then
Write-Debug "Decrypted file not equal to the original."
else
Write-Debug "Success."
end if
destroy loo_Crypt
destroy loo_Fac