Properties

$keyPairSize

$keyPairSize : 

The key pair size in bytes length property storage.

Type

Methods

__destruct()

__destruct() 

Container destructor.

__clone()

__clone() 

Container cloning via deep copy.

setKeyExchangeSize()

setKeyExchangeSize(integer  $keySize) : $this

Setter for the key pair size property.

Parameters

integer $keySize

The key size in bits.

Throws

\Exception

Validation errors.

Returns

$this —

The container object.

getKeyExchangeSize()

getKeyExchangeSize() : integer

Getter for the key pair size property.

Returns

integer —

The key pair size in bits.

generateExchangeRequestInformation()

generateExchangeRequestInformation() : \CryptoManana\DataStructures\ExchangeInformation

Generates fresh key exchange information for sending to the remote party.

Throws

\Exception

Validation errors.

Returns

\CryptoManana\DataStructures\ExchangeInformation

The key exchange information object.

generateExchangeResponseInformation()

generateExchangeResponseInformation(string  $prime, string  $generator) : \CryptoManana\DataStructures\ExchangeInformation

Generates fresh key exchange information based on the received prime and generator values.

Parameters

string $prime

The hexadecimal representation of a prime number, also knows as p.

string $generator

The hexadecimal generator number, a primitive root modulo of p, also known as g.

Throws

\Exception

Validation errors.

Returns

\CryptoManana\DataStructures\ExchangeInformation

The key exchange information object.

computeSharedSecret()

computeSharedSecret(string  $remotePublicKey, string  $localPrivateKey) : string

Computes the secret shared key for usage of both parties.

Parameters

string $remotePublicKey

The remote side's public key, based on the same prime and generator combination.

string $localPrivateKey

The local side's private key, based on the same prime and generator combination.

Throws

\Exception

Validation errors.

Returns

string —

The shared secret key.

validatePrivateKeyFormat()

validatePrivateKeyFormat(string  $privateKey) 

Internal method for the validation of the private key string representation format.

Parameters

string $privateKey

The private key input string.

Throws

\Exception

Validation errors.

validatePublicKeyFormat()

validatePublicKeyFormat(string  $publicKey) 

Internal method for the validation of the public key string representation format.

Parameters

string $publicKey

The public key input string.

Throws

\Exception

Validation errors.

validateKeyPairSize()

validateKeyPairSize(integer  $keySize) 

Internal method for asymmetric algorithm type validation.

Parameters

integer $keySize

The key size in bits.

Throws

\Exception

Validation errors.

generateKeyPairResource()

generateKeyPairResource(array  $settings) : resource

Internal method for generating a new key pair resource base on the given configuration.

Parameters

array $settings

The key generation configuration settings.

Throws

\Exception

Validation or system errors.

Returns

resource —

The private key resource containing all necessary information (prime, generator and public key).

getKeyPairInformation()

getKeyPairInformation(resource  $privateKeyResource) : array

Internal method for extracting the key pair details from from the private key resource.

Parameters

resource $privateKeyResource

The private key resource.

Throws

\Exception

Validation or system errors.

Returns

array —

The key pair details as an array.

exportPrivateKeyString()

exportPrivateKeyString(resource  $privateKeyResource) : string

Internal method for exporting the private key as a Base64 string from the private key resource.

Parameters

resource $privateKeyResource

The private key resource.

Throws

\Exception

Validation or system errors.

Returns

string —

The exported private key as a Base64 string.

generateKeyPair()

generateKeyPair(null|string  $prime = null, null|string  $generator = null) : array

Generates fresh Diffie–Hellman key exchange information.

Parameters

null|string $prime

The hexadecimal representation of a prime number or null to generate a new one.

null|string $generator

The hexadecimal representation of a generator number or null to generate a new one.

Throws

\Exception

Validation or generation errors.

Returns

array —

The generated key pair information.

buildExchangeInformation()

buildExchangeInformation(null|string  $prime = null, null|string  $generator = null) : \CryptoManana\DataStructures\ExchangeInformation

Generates and builds a key exchange information object.

Parameters

null|string $prime

The hexadecimal representation of a prime number or null to generate a new one.

null|string $generator

The hexadecimal representation of a generator number or null to generate a new one.

Throws

\Exception

Validation or generation errors.

Returns

\CryptoManana\DataStructures\ExchangeInformation

The key exchange information object.