About
An Advanced Encryption Standard (AES, also known as Rijndael) class to encrypt/decrypt data.
- Warning
- For encryption using the MAXON API see Stream Conversions Manual.
const Char plainText[] =
"O brave new world / That has such people in't!";
const Int32 length =
sizeof(plainText);
const Int32 blockSize = 256;
const Char key[32] = {
'7',
'c',
'3',
'0',
'e',
'0',
'0',
'b',
'b',
'6',
'2',
'7',
'1',
'4',
'9',
'5' };
const Int32 keyLength =
sizeof(key) * 8;
DebugAssert((keyLength == 128) || (keyLength == 192) || (keyLength == 256));
void* buffer = nullptr;
{
CopyMem(plainText, buffer, length);
if (aes && aes->
Init(blockSize, keyLength))
{
aes->
Encrypt(buffer, encryptedSize, key);
}
}
{
if (buffer && aes && aes->
Init(blockSize, keyLength))
{
if (aes->
Decrypt(buffer, encryptedSize, key))
{
}
}
}
Create
AES objects are created with the usual tools, see Entity Creation and Destruction Manual (Classic).
Use
- AES::Init(): Initializes the AES cipher to the given block length and key length.
- AES::CalcEncryptedDataSize(): Calculates the size of the data block (data size + encryption overhead).
- Note
- The encrypted data size is always equal or larger than the unencrypted data size.
Encryption / Decryption
- AES::Encrypt(): Encrypts a data block.
- AES::Decrypt(): Decrypts a data block.
- Note
- Use a buffer of encrypted data size for both operations.
- Warning
- It is recommended to fill the end of the buffer (encrypted size >= data size, so the part after the data to encrypt) with random values (e.g. via maxon::SecureRandom) to increase security.
Further Reading