Constants

ALGORITHM_NAME

ALGORITHM_NAME

The internal name of the algorithm.

KEY_SIZE

KEY_SIZE

The internal secret key size measured in raw bytes length for the algorithm

BLOCK_SIZE

BLOCK_SIZE

The internal operational block size measured in raw bytes length for the algorithm

IV_SIZE

IV_SIZE

The internal initialization vector (IV) size measured in raw bytes length for the algorithm

Properties

$validBlockModes

$validBlockModes : array

List of valid block operation modes.

Type

array — Block mode codes.

$key

$key : string

The encryption/decryption secret key property storage.

Type

string — The encryption/decryption secret key string value.

$cipherFormat

$cipherFormat : integer

The output cipher format property storage.

Type

integer — The output cipher format integer code value.

$iv

$iv : string

The initialization vector (IV) string property storage.

Type

string — The initialization vector (IV) string value.

$mode

$mode : string

The block encryption operation mode string property.

Type

string — The block encryption operation mode string value.

$padding

$padding : integer

The final block padding operation property.

Type

integer — The final block padding operation integer code value.

Methods

setInitializationVector()

setInitializationVector(string  $iv) : $this

Setter for the initialization vector (IV) string property.

Parameters

string $iv

The initialization vector (IV) string.

Throws

\Exception

Validation errors.

Returns

$this —

The symmetric encryption algorithm object.

getInitializationVector()

getInitializationVector() : string

Getter for the initialization vector (IV) string property.

Returns

string —

The initialization vector (IV) string.

setBlockOperationMode()

setBlockOperationMode(string  $mode) : $this

Setter for the block encryption operation mode string property.

Parameters

string $mode

The block operation mode string.

Throws

\Exception

Validation errors.

Returns

$this —

The symmetric encryption algorithm object.

getBlockOperationMode()

getBlockOperationMode() : string

Getter for the block encryption operation mode string property.

Returns

string —

The block operation mode string.

setPaddingStandard()

setPaddingStandard(integer  $padding) : $this

Setter for the final block padding operation property.

Parameters

integer $padding

The padding standard integer code value.

Throws

\Exception

Validation errors.

Returns

$this —

The symmetric encryption algorithm object.

getPaddingStandard()

getPaddingStandard() : integer

Getter for the final block padding operation property.

Returns

integer —

The padding standard integer code value.

encryptObject()

encryptObject(object|\stdClass  $object) : string

Encrypts the serialized value of the given object.

Parameters

object|\stdClass $object

The object for encryption.

Throws

\Exception

Validation errors.

Returns

string —

The encrypted serialized object as a string.

decryptObject()

decryptObject(string  $cipherData) : object|\stdClass

Decrypts the encrypted value of the given object.

Parameters

string $cipherData

The encrypted serialized object as a string.

Throws

\Exception

Validation errors.

Returns

object|\stdClass —

The decrypted and unserialized object.

encryptFile()

encryptFile(string  $filename) : string

Encrypts the content of a given plain file.

Parameters

string $filename

The full path and name of the file for encryption.

Throws

\Exception

Validation errors.

Returns

string —

The encrypted file content.

decryptFile()

decryptFile(string  $filename) : string

Decrypts the content of a given encrypted file.

Parameters

string $filename

The full path and name of the file for encryption.

Throws

\Exception

Validation errors.

Returns

string —

The decrypted file content.

__construct()

__construct() 

Block cipher algorithm constructor.

setSecretKey()

setSecretKey(string  $key) : $this

Setter for the secret key string property.

Parameters

string $key

The encryption key string.

Throws

\Exception

Validation errors.

Returns

$this —

The symmetric encryption algorithm object.

getSecretKey()

getSecretKey() : string

Getter for the secret key string property.

Returns

string —

The encryption key string.

setCipherFormat()

setCipherFormat(integer  $cipherFormat) : $this

Setter for the output cipher format code property.

Parameters

integer $cipherFormat

The output cipher format code.

Throws

\Exception

Validation errors.

Returns

$this —

The encryption algorithm object.

getCipherFormat()

getCipherFormat() : integer

Getter for the output cipher format code property.

Returns

integer —

The output cipher format code.

__debugInfo()

__debugInfo() : array

Get debug information for the class instance.

Returns

array —

Debug information.

encryptData()

encryptData(string  $plainData) : string

Encrypts the given plain data.

Parameters

string $plainData

The plain input string.

Throws

\Exception

Validation errors.

Returns

string —

The cipher/encrypted data.

decryptData()

decryptData(string  $cipherData) : string

Decrypts the given cipher data.

Parameters

string $cipherData

The encrypted input string.

Throws

\Exception

Validation errors.

Returns

string —

The decrypted/plain data.

validateBlockModeSupport()

validateBlockModeSupport(string  $mode) 

Internal method for the validation of the system support of the given block operation mode.

Parameters

string $mode

The block mode name.

Throws

\Exception

Validation errors.

fetchAlgorithmMethodName()

fetchAlgorithmMethodName() : string

Fetch the correctly formatted internal encryption algorithm method name.

Returns

string —

The symmetric encryption algorithm standard.

validatePlainDataForEncryption()

validatePlainDataForEncryption(string  $plainData) 

Internal method for the validation of plain data used at encryption operations.

Parameters

string $plainData

The plain input string.

Throws

\Exception

Validation errors.

validateCipherDataForDecryption()

validateCipherDataForDecryption(string  $cipherData) 

Internal method for the validation of cipher data used at decryption operations.

Parameters

string $cipherData

The encrypted input string.

Throws

\Exception

Validation errors.

encryptionFormat()

encryptionFormat(string  $bytes) 

Internal method for converting format after encryption operations.

Parameters

string $bytes

The bytes for conversion.

decryptionFormatHex()

decryptionFormatHex(string  $bytes) 

Internal method for converting from HEX formatted string after decryption operations.

Parameters

string $bytes

The bytes for conversion.

decryptionFormatBase64()

decryptionFormatBase64(string  $bytes) 

Internal method for converting from Base64 formatted string after decryption operations.

Parameters

string $bytes

The bytes for conversion.

decryptionFormat()

decryptionFormat(string  $bytes) 

Internal method for converting format after decryption operations.

Parameters

string $bytes

The bytes for conversion.

changeOutputFormat()

changeOutputFormat(string  $bytes, boolean|integer|null  $direction = true) : string

Internal method for converting the output format representation via the chosen format.

Parameters

string $bytes

The bytes for conversion.

boolean|integer|null $direction

Flag for encryption direction (encrypt => true or decrypt => false).

Returns

string —

The formatted bytes.