aes_enc(t)
Encrypts data using the AES algorithm with the specified key and key size.
Syntax
aes_enc(t);
Arguments
| Name | Description |
|---|---|
|
t |
A table that specifies the message to encrypt, the encryption key, and the key size. |
Events
Applicable in all events.
Operations
The function performs AES encryption on the provided message using the specified key.
|
Field |
Type |
Required |
Description |
|---|---|---|---|
|
message |
String |
Yes |
The plaintext string to be encrypted. |
|
key |
String |
Yes |
The encryption key. Length must match the specified key size. |
|
size |
Integer |
Yes |
The AES key size. Must be 128, 192, or 256. |
Key Length Requirements:
size=128: Key must be 16 bytes long
size=192: Key must be 24 bytes long
size=256: Key must be 32 bytes long
Example
when HTTP_REQUEST {
t={};
t["message"] = "MICK-TEST";
t["key"] = "aaaaaaaaaabbbbbb" --16bit
t["size"]= 128 -- 128, 192, or 256, the corresponding key length is 16, 24, and 32
enc = aes_enc(t)
debug("The aes_enc output to HEX\n %s\n",to_HEX(enc));
}
Notes:
- Message: The plaintext string to be encrypted. (Note: Function will handle PKCS#7 padding internally).
- Key: A binary string representing the encryption key. Its length MUST be 16, 24, or 32 bytes for AES-128, AES-192, or AES-256 respectively. WARNING: Do not directly use a text password as the key. Use a Key Derivation Function (KDF) like PBKDF2 to create a secure key from a password.
- Size: The AES key size. Must be 128, 192, or 256.
- Output: The encrypted output is a binary string. Use the `to_HEX()` function to convert it to a hexadecimal representation for debugging or transmission.
Supported Version
FortiADC version 5.2.x and later.