class Cipher (View source)

Class providing cipher algorithms

Constants

MODE_ECB

MODE_CBC

MODE_CFB

MODE_OFB

MODE_CTR

MODE_GCM

MODE_CCM

MODE_XTS

Methods

static string
getAlgorithms(bool $aliases = false, string $prefix = null)

Returns cipher algorithms

static bool
hasAlgorithm(string $algorithm)

Finds out whether algorithm exists

static bool
hasMode(int $mode)

Finds out whether the cipher mode is defined in the used OpenSSL library

static 
__callStatic(string $name, array $arguments)

Cipher magic method for calling static methods

__construct(string $algorithm, int $mode = null, string $key_size = null)

Cipher constructor

string
getAlgorithmName()

Returns cipher algorithm string

bool
encryptInit(string $key, string $iv = null)

Initializes cipher encryption

string
encryptUpdate(string $data)

Updates cipher encryption

string
encryptFinish()

Finalizes cipher encryption

string
encrypt(string $data, string $key, string $iv = null)

Encrypts text to ciphertext

null
decryptInit(string $key, string $iv = null)

Initializes cipher decryption

string
decryptUpdate(string $data)

Updates cipher decryption

string
decryptFinish()

Finalizes cipher decryption

string
decrypt(string $data, string $key, string $iv = null)

Decrypts ciphertext to decrypted text

int
getBlockSize()

Returns cipher block size

int
getKeyLength()

Returns cipher key length

int
getIVLength()

Returns cipher IV length

int
getMode()

Returns cipher mode

string
getTag()

Returns authentication tag

bool
setTag(string $tag)

Sets authentication tag

bool
setTagLength(int $tag_length)

Set authentication tag length

bool
setAAD(string $aad)

Sets additional application data for authenticated encryption

Details

static string getAlgorithms(bool $aliases = false, string $prefix = null)

Returns cipher algorithms

Parameters

bool $aliases
string $prefix

Return Value

string

static bool hasAlgorithm(string $algorithm)

Finds out whether algorithm exists

Parameters

string $algorithm

Return Value

bool

static bool hasMode(int $mode)

Finds out whether the cipher mode is defined in the used OpenSSL library

Parameters

int $mode

Return Value

bool

static __callStatic(string $name, array $arguments)

Cipher magic method for calling static methods

Parameters

string $name
array $arguments

__construct(string $algorithm, int $mode = null, string $key_size = null)

Cipher constructor

Parameters

string $algorithm
int $mode
string $key_size

string getAlgorithmName()

Returns cipher algorithm string

Return Value

string

bool encryptInit(string $key, string $iv = null)

Initializes cipher encryption

Parameters

string $key
string $iv

Return Value

bool

string encryptUpdate(string $data)

Updates cipher encryption

Parameters

string $data

Return Value

string

string encryptFinish()

Finalizes cipher encryption

Return Value

string

string encrypt(string $data, string $key, string $iv = null)

Encrypts text to ciphertext

Parameters

string $data
string $key
string $iv

Return Value

string

null decryptInit(string $key, string $iv = null)

Initializes cipher decryption

Parameters

string $key
string $iv

Return Value

null

string decryptUpdate(string $data)

Updates cipher decryption

Parameters

string $data

Return Value

string

string decryptFinish()

Finalizes cipher decryption

Return Value

string

string decrypt(string $data, string $key, string $iv = null)

Decrypts ciphertext to decrypted text

Parameters

string $data
string $key
string $iv

Return Value

string

int getBlockSize()

Returns cipher block size

Return Value

int

int getKeyLength()

Returns cipher key length

Return Value

int

int getIVLength()

Returns cipher IV length

Return Value

int

int getMode()

Returns cipher mode

Return Value

int

string getTag()

Returns authentication tag

Return Value

string

bool setTag(string $tag)

Sets authentication tag

Parameters

string $tag

Return Value

bool

bool setTagLength(int $tag_length)

Set authentication tag length

Parameters

int $tag_length

Return Value

bool

bool setAAD(string $aad)

Sets additional application data for authenticated encryption

Parameters

string $aad

Return Value

bool