Constants

ALGORITHM_NAME

ALGORITHM_NAME

The internal name of the algorithm.

KEY_SIZE

KEY_SIZE

The internal key size measured in raw bits length for the algorithm

Properties

$padding

$padding : integer

The asymmetric data padding operation property.

Type

integer — The data padding operation integer code value.

$cipherFormat

$cipherFormat : integer

The output cipher format property storage.

Type

integer — The output cipher format integer code value.

$useChunks

$useChunks : boolean

Flag for enabling/disabling data processing via chunks.

Type

boolean — Flag to for data processing via chunks.

$privateKey

$privateKey : string

The private key string property storage.

Type

string — The private key string value.

$publicKey

$publicKey : string

The public key string property storage.

Type

string — The public key string value.

Methods

__construct()

__construct() 

Asymmetrical algorithm constructor.

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

setPaddingStandard()

setPaddingStandard(integer  $padding) : $this

Setter for the asymmetric data padding operation property.

Parameters

integer $padding

The padding standard integer code value.

Throws

\Exception

Validation errors.

Returns

$this —

The asymmetric encryption algorithm object.

getPaddingStandard()

getPaddingStandard() : string

Getter for the asymmetric data padding operation property.

Returns

string —

The padding standard integer code value.

getPaddingReservedSize()

getPaddingReservedSize() : integer

Getter for the minimum size of the padding bytes that are required/reserved by the algorithm.

Returns

integer —

The minimum reserved size of the padding bytes.

enableChunkProcessing()

enableChunkProcessing() : $this

Enable long data processing via small chunks.

Returns

$this —

The asymmetric encryption algorithm object.

disableChunkProcessing()

disableChunkProcessing() : $this

Disable long data processing via small chunks.

Returns

$this —

The asymmetric encryption algorithm object.

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.

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.

setKeyPair()

setKeyPair(\CryptoManana\DataStructures\KeyPair  $keyPair) : $this

Setter for the whole key pair as an array.

Parameters

\CryptoManana\DataStructures\KeyPair $keyPair

The private and public key pair as an object.

Throws

\Exception

Validation errors.

Returns

$this —

The encryption/signature algorithm object.

getKeyPair()

getKeyPair() : \CryptoManana\DataStructures\KeyPair

Getter for the whole key pair as an array.

Throws

\Exception

Validation errors.

Returns

\CryptoManana\DataStructures\KeyPair

The private and public key pair as an object.

setPrivateKey()

setPrivateKey(string  $privateKey) : $this

Setter for the private key string property.

Parameters

string $privateKey

The private key string.

Throws

\Exception

Validation errors.

Returns

$this —

The encryption/signature algorithm object.

getPrivateKey()

getPrivateKey() : string

Getter for the private key string property.

Returns

string —

The private key string.

setPublicKey()

setPublicKey(string  $publicKey) : $this

Setter for the public key string property.

Parameters

string $publicKey

The public key string.

Throws

\Exception

Validation errors.

Returns

$this —

The encryption/signature algorithm object.

getPublicKey()

getPublicKey() : string

Getter for the public key string property.

Returns

string —

The public key string.

checkIfThePrivateKeyIsSet()

checkIfThePrivateKeyIsSet() 

Checks if the private key is present.

Throws

\Exception

If there is no private key set.

checkIfThePublicKeyIsSet()

checkIfThePublicKeyIsSet() 

Checks if the public key is present.

Throws

\Exception

If there is no public key set.

validatePlainData()

validatePlainData(string  $plainData) 

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

Parameters

string $plainData

The plain input string.

Throws

\Exception

Validation errors.

validateCipherOrSignatureData()

validateCipherOrSignatureData(string  $cipherOrSignatureData) 

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

Parameters

string $cipherOrSignatureData

The encrypted input string or a signature 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.

validatePrivateKeyResource()

validatePrivateKeyResource(string  $privateKey) : string

Internal method for the validation of the private key resource.

Parameters

string $privateKey

The private key input string.

Throws

\Exception

Validation errors.

Returns

string —

The extracted public key string from the private key resource.

validatePublicKeyResource()

validatePublicKeyResource(string  $publicKey) 

Internal method for the validation of the public key resource.

Parameters

string $publicKey

The public key input string.

Throws

\Exception

Validation errors.

validateKeyPair()

validateKeyPair(string  $privateKey, string  $publicKey) 

Internal method for the validation of the private and public key pair string representations.

Parameters

string $privateKey

The private key input string.

string $publicKey

The public key input string.

Throws

\Exception

Validation errors.