Tcl
Tcl
Workaround for the deprecated Crypt2.DecryptBytesENC method
Shows how to replace the deprecated DecryptBytesENC method. (Chilkat is moving away from the use of CkByteData.)Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
set crypt [new_CkCrypt2]
CkCrypt2_put_CryptAlgorithm $crypt "aes"
CkCrypt2_put_CipherMode $crypt "cbc"
CkCrypt2_put_KeyLength $crypt 128
CkCrypt2_put_PaddingScheme $crypt 0
CkCrypt2_SetEncodedKey $crypt "000102030405060708090A0B0C0D0E0F" "hex"
CkCrypt2_SetEncodedIV $crypt "000102030405060708090A0B0C0D0E0F" "hex"
set success 0
# ------------------------------------------------------------------------
# The EncryptBytesENC and DecryptBytesENC methods are deprecated:
set unencryptedBytes [new_CkByteData]
CkByteData_appendEncoded $unencryptedBytes "AABBCCDDEEFF01020304" "hex"
set decryptedBytes [new_CkByteData]
CkCrypt2_put_EncodingMode $crypt "hex"
set encryptedAsHex [CkCrypt2_encryptBytesENC $crypt $unencryptedBytes]
puts "Encrypted: $encryptedAsHex"
set success [CkCrypt2_DecryptBytesENC $crypt $encryptedAsHex $decryptedBytes]
# ------------------------------------------------------------------------
# Replace the above CkByteData usage with the following code:
# (Chilkat is moving away from using CkByteData)
set bd [new_CkBinData]
CkBinData_AppendEncoded $bd "AABBCCDDEEFF01020304" "hex"
# in-place encrypt, then get as hex.
CkCrypt2_EncryptBd $crypt $bd
set encryptedAsHex [CkBinData_getEncoded $bd "hex"]
puts "Encrypted: $encryptedAsHex"
# load from hex, then decrypt.
set bd2 [new_CkBinData]
CkBinData_AppendEncoded $bd2 $encryptedAsHex "hex"
CkCrypt2_DecryptBd $crypt $bd2
puts "Decrypted: [CkBinData_getEncoded $bd2 hex]"
delete_CkCrypt2 $crypt
delete_CkByteData $unencryptedBytes
delete_CkByteData $decryptedBytes
delete_CkBinData $bd
delete_CkBinData $bd2