Some notes on the changes in CryptoSys PKI Pro v11.1 released 25 March 2016.
4 June 2016: An improvement in CryptoSys PKI Pro v11.0 we forgot to mention.
The new functions CIPHER_EncryptBytes2
and CIPHER_DecryptBytes2
are now the recommended way to do all symmetrical encryption.
For now very-old historical reasons, the other encrypt-bytes functions all assumed that the user would pass byte arrays of the correct length for the input, key and IV. The new "Bytes2" versions do explicit checks for the lengths of all byte arrays. This is especially convenient (and safer) when used internally in the interfaces for C# and Python (did we mention we've just released a Python interface?).
We were going to use the name CIPHER_EncryptBytesEx
but then realised how it looked in all lower-case.
TDEA_BytesMode(lpOutput, lpInput, nDataLen, lpKey, fEncrypt, szMode, lpIV)
CIPHER_Bytes(fEncrypt, lpOutput, lpInput, nDataLen, lpKey, lpIV, szAlgAndMode, nOptions)
TDEA_BytesMode
but with option to specify encryption algorithm (Tdea/Aes).
No padding.
Returns 0 on success.
No checks on length of key or IV. @deprecated.
CIPHER_EncryptBytesPad(lpOutput, nOutBytes, lpInput, nInputLen, lpKey, lpIV, szAlgModePad, nOptions)
CIPHER_EncryptBytes2(lpOutput, nOutBytes, lpInput, nInputLen, lpKey, nKeylen, lpV, nIvLen, szAlgModePad, nOptions)
CIPHER_EncryptBytesPad
but with explicit checks on length of key and IV.
To get the same behaviour as CIPHER_Bytes
with no padding added or removed in ECB/CBC mode, use the "NoPad" option.
All the following statements do exactly the same.
Dim key() As Byte Dim iv() As Byte Dim pt() As Byte Dim ct() As Byte Dim ptlen As Long Dim ctlen As Long Dim keylen As Long Dim ivlen As Long Dim r As Long ' /SNIP/ See full code below r = TDEA_BytesMode(ct(0), pt(0), ptlen, key(0), ENCRYPT, "CBC", iv(0)) Debug.Assert(r = 0) r = CIPHER_Bytes(ENCRYPT, ct(0), pt(0), ptlen, key(0), iv(0), "tdea/cbc", 0) Debug.Assert(r = 0) ctlen = CIPHER_EncryptBytesPad(ct(0), ctlen, pt(0), ptlen, key(0), iv(0), "tdea/cbc/nopad", 0) Debug.Assert(ctlen > 0) ctlen = CIPHER_EncryptBytes2(ct(0), ctlen, pt(0), ptlen, key(0), keylen, iv(0), ivlen, "tdea/cbc/nopad", 0) Debug.Assert(ctlen > 0)
Yes. The new functions CIPHER_FileEncrypt
and CIPHER_FileDecrypt
are now the recommended functions to perform symmetrical encryption on files.
They have explicit checks on the lengths of the key and IV, which is a good thing.
But wait, there's more! These two new functions also allow you to use different padding schemes in ECB and CBC mode (the deprecated functions always used PKCS5Padding). Plus they allow you prepend or prefix the IV at the beginning of the output file so there is no need to transmit it separately.
All the following statements do exactly the same, encrypting the file using Triple DES in CBC mode with (default) PKCS5Padding.
r = TDEA_File(fileout, filein, key(0), ENCRYPT, "CBC", iv(0)) r = CIPHER_File(ENCRYPT, fileout, filein, key(0), iv(0), "tdea/cbc", 0) r = CIPHER_FileEncrypt(fileout, filein, key(0), keylen, iv(0), ivlen, "tdea/cbc", 0)
Should you want to encrypt using aes192/cbc/OneAndZeroes with the IV prefixed to the output, you can do the following (making sure you pass the correct key and IV lengths)
r = CIPHER_FileEncrypt(fileout, filein, key(0), keylen, iv(0), ivlen, "aes192/cbc/OneAndZeroes", PKI_IV_PREFIX)
These safer encryption functions are already substituted in the C# code for the
Cipher Class
.
The old Tdea Class
methods are now deprecated.
Test code: test_cipher_comp.bas. Download source (zipped 1.4 kB). Expected output in the immediate window:
test_CIPHER_comp ptlen=32 CT=204011F986E35647199E47AF391620C5BB9A5BCFC86DB0BB2C577D7322162509 CT=204011F986E35647199E47AF391620C5BB9A5BCFC86DB0BB2C577D7322162509 CT=204011F986E35647199E47AF391620C5BB9A5BCFC86DB0BB2C577D7322162509 CT=204011F986E35647199E47AF391620C5BB9A5BCFC86DB0BB2C577D7322162509 test_CIPHER_File_comp PT=616263 CT=793DEC494A1FAA0A CT=793DEC494A1FAA0A CT=793DEC494A1FAA0A CT=FEDCBA9876543210FEDCBA9876543210FC81FCF7AB8D89C5196D5393FB00D624
For more information, or to comment on this page, please send us a message.
This page last updated 15 August 2025