Aes

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

since

1.0

package

Application

Methods

__construct

Initialise the AES encryption object.

__construct(string key, int strength = 128, string mode = 'cbc', string priority = 'openssl') : mixed

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

intBit 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

Response

mixed

decryptString

Decrypts a ciphertext into a plaintext string using AES

decryptString(string stringToDecrypt, bool base64encoded = true) : string

Arguments

stringToDecrypt

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

base64encoded

boolShould I Base64-decode the data before decryption?

Response

stringThe plain text string

encryptString

Encrypts a string using AES

encryptString(string stringToEncrypt, bool base64encoded = true) : string

Arguments

stringToEncrypt

stringThe plaintext to encrypt

base64encoded

boolShould 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(int blockSize, string iv) : string

Arguments

blockSize

intBlocksize to process

iv

stringIV

Response

string

isSupported

Is AES encryption supported by this PHP installation?

isSupported() : bool
static

Response

bool

setPassword

Sets the password for this instance.

setPassword(string password, bool 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

boolTrue 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.

Type(s)

AesInterface