.NET RijndaelManaged to Chilkat Equivalent

Here’s a snippet of C# code to do AES encryption.  What is the equivalent in Chilkat?


Dim cspRijndael As New System.Security.Cryptography.RijndaelManaged
csCryptoStream = New CryptoStream(fsOutput, cspRijndael.CreateEncryptor(bytKey, bytIV), CryptoStreamMode.Write)

“Rijndael” is the name of the encryption algorithm, and (essentially) “AES” is Rijndael limited to the choices of 128, 192, or 256 bits.

Rijndael/AES is a symmetric block encryption algorithm, and the size of the IV is always equal to the block size of the algorithm.  The block size for AES is 16-bytes.  This is the block size regardless of key size (whether key is 128-bits, 192-bits, or 256-bits).  Therefore, in the above code, bytIV should always be 16 bytes.   The length of the bytKey byte array determines the key size, and it should be 16 bytes, 24 bytes, or 32 bytes.

The default cipher mode for RijndaelManaged is “CBC”.   (See https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rijndaelmanaged.mode)

The default padding is PKCS7 (See https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rijndaelmanaged.padding )

Therefore, the equivalent code in Chilkat is:
decrypt.CryptAlgorithm = "aes"
decrypt.CipherMode = "cbc"
decrypt.KeyLength = 256
decrypt.PaddingScheme = 0
decrypt.SetEncodedIV ivHex,"hex"
decrypt.SetEncodedKey keyHex,"hex"

Your IV should be 16 bytes encoded as you desire.  The above code snippet specifies “hex”, but could be base64, or other encodings.

The PaddingScheme = 0 is the default, which is PKCS7 padding.  (See the Chilkat online reference documentation for Crypt.)

The KeyLength is in number of bits, and the number of bytes passed to SetEncodedKey should equal the KeyLength/8.