Skip to main content
Version: 0.3.0

AES

AES block size will be determined be the size of the key. Here are the block size for the variout key sizes:

Key sizeBlock size
16 bytes128 bits
24 bytes192 bits
32 bytes256 bits

IV must be 16 bytes long.

Key & IV

The easiest way to obtain a key or an iv is by using the randomBytes utility function.

const aes_key = Cryptopp.utils.randomBytes(32);
const aes_iv = Cryptopp.utils.randomBytes(16);

Key & IV can be also passed as a string. Both the string key and string iv must be HEX encoded because UTF-8 allows variable length, multi-byte characters, so a string that is 16 characters long may not be 16 bytes long.

Encrypt

Cryptopp.AES.encrypt(message, key, iv, 'cbc');

Parameters

ParameterTypeRequiredDefault
datastring
ArrayBuffer
keyHEX-encoded string
ArrayBuffer
ivHEX-encoded string
ArrayBuffer
mode"ecb"
"cbc"
"cbc_cts"
"cfb"
"ofb"
"ctr"
"xts"
encodeTo"hex"
"base64"
"base64url"
"base64"

Returns: Based on data input type: ArrayBuffer or encoded string - base64 by default

Decrypt

Cryptopp.AES.decrypt(encrypted_message, key, iv, 'cbc');

Parameters

ParameterTypeRequiredDefault
datastring
ArrayBuffer
keyHEX-encoded string
ArrayBuffer
ivHEX-encoded string
ArrayBuffer
modeecb
cbc
cfb
ofb
ctr
dataEncodingutf8
hex
base64
base64url
base64

Returns: Based on data input type: ArrayBuffer or utf8 string