Method AesCrypt():new() Professional

Creates an instance of the AesCrypt class.

Syntax
AesCrypt():new([<cKey>|<oKey>], [<nMode>], [<cIV>]) --> oAesCrypt
Parameters
<cKey>
The encryption buffer is prepared by passing the key. The key is used to encrypt and decrypt the data. The length of the key must be either 128, 192 or 256 bit. <cKey> is interpreted as a binary character string. If this parameter is not passed, it must later be set by calling :setKey().
<oKey>
Alternativly, an object of the class SecureKey() can be passed as the key. If this parameter is not passed, it must later be set by calling :setKey().
<nMode>
Sets the crypting operation mode. Possible values are CRYPT_OP_ECB, CRYPT_OP_CBC and CRYPT_OP_CTS.
Operation modes
nMode Operation mode name Minimal result size
CRYPT_OP_ECB *) Electronic CodeBook one block
CRYPT_OP_CBC Cipher Block Chaining two blocks
CRYPT_OP_CTS CBC combined with cipher text stealing two blocks
  1. Default
For the modes CRYPT_OP_CBC and CRYPT_OP_CTS an initialization vector (IV) is required. By default (CRYPT_AUTO_LEADING_IV), an initialization vector is generated automatically and encrypted. This IV is then contained in the first 16 bytes of the encrypted message. For decryption, the encrypted IV is expected in the first 16 bytes of the encrypted message, too. A sub-mode can optionally be specified for controlling the generation and placement of the IV by adding one of the values from the following table. Hence, an <nMode> parameter of CRYPT_OP_CBC+CRYPT_AUTO_LEADING_IV defines Cipher Block Chaining with a leading IV which is automatically generated.
Operation sub-modes
nMode Description
CRYPT_AUTO_LEADING_IV *) Automatically generated IV, precedes encrypted message.
CRYPT_AUTO_TRAILING_IV Automatically generated IV, follows encrypted message.
CRYPT_CUSTOM_LEADING_IV <cIV> parameter used, precedes encrypted message.
CRYPT_CUSTOM_TRAILING_IV <cIV> parameter used, follows encrypted message.
  1. Default
CRYPT_AUTO_LEADING_IV: The initialization vector is chosen automatically and randomly for encryption. After encryption, the IV is contained in the first 16 bytes of the encrypted message. For decryption the IV is expected in the first 16 bytes of the encrypted message.
CRYPT_AUTO_TRAILING_IV: The initialization vector is chosen automatically and randomly for the encryption. After encryption, the IV is contained in the last 16 bytes of the encrypted message. For decryption the IV is expected in the last 16 bytes of the encrypted message.
CRYPT_CUSTOM_LEADING_IV: For encryption the initialization vector is passed in the parameter cIV and is contained in the first 16 bytes of the encrypted message. For decryption the IV is expected in the first 16 bytes of the encrypted message.
CRYPT_CUSTOM_TRAILING_IV: For encryption the initialization vector is passed in the parameter cIV and is contained in the last 16 bytes of the encrypted message. For decryption the IV is expected in the last 16 bytes of the encrypted message.
<cIV>
In the sub modes CRYPT_CUSTOM_LEADING_IV and CRYPT_CUSTOM_TRAILING_IV, an initialization vector must be passed in the parameter <cIV>. The initialization vector is a binary string of 16 bytes (128 bits) length and is used for encryption in CRYPT_OP_CBC and CRYPT_OP_CTS modes.
Return

The class method :new() returns an AesCrypt object.

Description

If :new() is called with no parameters, the method :setKey() must be called before the instance can be used to encrypt or decrypt data.

Feedback

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.