Class AesCrypt() Professional

Class function of the AesCrypt class


The AesCrypt class provides the interface for AES encryption/decryption. Its role is to provide a cryptographic implementation of AES, the Advanced Encryption Standard as announced by NIST, effective May 26 2002. Detailed information about AES encryption can be found in the corresponding Wikipedia article under

The class AesCrypt is derived from the class CryptProvider. This class is not yet documented because it is an abstract, which cannot be instantiated.

AES uses the Rijndael algorithm to encrypt/decrypt data. It is a block code where the block size is always 128 bit. The key length can be 128, 192 or 256 bit.

The AesCrypt() class supports AES encryption in the ECB (electronic code book), CBC (cipher block chaining) and CTS (CBC with cipher text stealing) modes.

In general, in ECB and CBC mode, the length of the message to be encrypted must be a multiple of the block length. In CTS mode the length of the message must be at least 2 block. In all modes, the :prepareBuffer() method can be used to extend the message to the correct length.

In ECB mode the encrypted message has the same length as the plaintext message. In CBC and CTS modes, encryption requires an initialization vector that becomes part of the encrypted message. Thus, in these modes (CBC and CTS), the encrypted message is longer than the original message by the IV. For more information, see the documentation for the :new() method.

SecureKey():destroy() can be called right after setting the key object, either after :new() or :setKey().

Class methods
Creates an instance of the AesCrypt class.
Encrypts a buffer using a key.
Decrypts a previously encrypted buffer using a key.
Prepares a buffer for encryption.
Provides a key used for encryption or decryption.
AesCrypt handling
// In this example, AesCrypt() is used 
// to encrypt a single buffer 

#include "" 

   LOCAL oAes 
   LOCAL oKey 
   LOCAL cResult 

   // generate a key and print out 
   oKey := SecureKey():generate() 
   ? oKey:toString() 

   // create AesCrypt()-instance using the key 
   oAes := AesCrypt():new(oKey) 

   // destroy key value 

   // prepare input buffer length 
   // encrypt buffer 
   cResult := oAes:encrypt(cBuffer) 
   ? cResult 

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.