Aes

A simple implementation of AES-128, AES-192 and AES-256 encryption using the high performance mcrypt library.

since

1.0

Methods

__construct

Initialise the AES encryption object.

__construct(string $key, integer $strength = 128, string $mode = 'cbc', string $priority = 'openssl') 

Note: If the key is not 16 bytes this class will do a stupid key expansion for legacy reasons (produce the SHA-256 of the key string and throw away half of it).

Arguments

$key

stringThe encryption key (password). It can be a raw key (16 bytes) or a passphrase.

$strength

integerBit strength (128, 192 or 256) – ALWAYS USE 128 BITS. THIS PARAMETER IS DEPRECATED.

$mode

stringEncryption mode. Can be ebc or cbc. We recommend using cbc.

$priority

stringPriority which adapter we should try first

decryptString

Decrypts a ciphertext into a plaintext string using AES

decryptString(string $stringToDecrypt, boolean $base64encoded = true) : string

Arguments

$stringToDecrypt

stringThe ciphertext to decrypt. The first 16 bytes of the raw string must contain the IV (initialisation vector).

$base64encoded

booleanShould I Base64-decode the data before decryption?

Response

stringThe plain text string

encryptString

Encrypts a string using AES

encryptString(string $stringToEncrypt, boolean $base64encoded = true) : string

Arguments

$stringToEncrypt

stringThe plaintext to encrypt

$base64encoded

booleanShould I Base64-encode the result?

Response

stringThe cryptotext. Please note that the first 16 bytes of the raw string is the IV (initialisation vector) which is necessary for decoding the string.

getExpandedKey

Get the expanded key

getExpandedKey(integer $blockSize, string $iv) : string

Arguments

$blockSize

integerBlocksize to process

$iv

stringIV

Response

string

isSupported

Is AES encryption supported by this PHP installation?

isSupported() : boolean
static

Response

boolean

setPassword

Sets the password for this instance.

setPassword(string $password, boolean $legacyMode = false) : void

WARNING: Do not use the legacy mode, it's insecure

since

4.0.0

Arguments

$password

stringThe password (either user-provided password or binary encryption key) to use

$legacyMode

booleanTrue to use the legacy key expansion. We recommend against using it.

Properties

key

The cipher key.

Type(s)

string

adapter

The AES encryption adapter in use.