PHP implementation of the Diffie-Hellman public key encryption algorithm.

Allows two unassociated parties to establish a joint shared secret key to be used in encrypting subsequent communications.

category Zend
package Zend_Crypt

 Methods

Constructor; if set construct the object using the parameter array to set values for Prime, Generator and Private.

__construct(string $prime, string $generator, string $privateKey, string $privateKeyFormat) 

If a Private Key is not set, one will be generated at random.

Parameters

$prime

string

$generator

string

$privateKey

string

$privateKeyFormat

string

Compute the shared secret key based on the public key received from the the second party to this transaction.

computeSecretKey(string $publicKey, string $publicKeyFormat, string $secretKeyFormat) : string

This should agree to the secret key the second party computes on our own public key. Once in agreement, the key is known to only to both parties. By default, the function expects the public key to be in binary form which is the typical format when being transmitted.

If you need the binary form of the shared secret key, call getSharedSecretKey() with the optional parameter for Binary output.

Parameters

$publicKey

string

$publicKeyFormat

string

$secretKeyFormat

string

Exceptions

\Zend\Crypt\Exception\InvalidArgumentException
\Zend\Crypt\Exception\RuntimeException

Returns

string

Generate own public key.

generateKeys() : \Zend\Crypt\PublicKey\DiffieHellman

If a private number has not already been set, one will be generated at this stage.

Exceptions

\Zend\Crypt\Exception\RuntimeException

Returns

Getter for the value of the generator number

getGenerator(string $format) : string

Parameters

$format

string

Exceptions

\Zend\Crypt\Exception\InvalidArgumentException

Returns

string

Getter for the value of the prime number

getPrime(string $format) : string

Parameters

$format

string

Exceptions

\Zend\Crypt\Exception\InvalidArgumentException

Returns

string

Getter for the value of the private number

getPrivateKey(string $format) : string

Parameters

$format

string

Returns

string

Returns own public key for communication to the second party to this transaction

getPublicKey(string $format) : string

Parameters

$format

string

Exceptions

\Zend\Crypt\Exception\InvalidArgumentException

Returns

string

Return the computed shared secret key from the DiffieHellman transaction

getSharedSecretKey(string $format) : string

Parameters

$format

string

Exceptions

\Zend\Crypt\Exception\InvalidArgumentException

Returns

string

Check whether a private key currently exists.

hasPrivateKey() : bool

Returns

bool

Setter for the value of the generator number

setGenerator(string $number) : \Zend\Crypt\PublicKey\DiffieHellman

Setter for the value of the prime number

setPrime(string $number) : \Zend\Crypt\PublicKey\DiffieHellman

Setter for the value of the private number

setPrivateKey(string $number, string $format) : \Zend\Crypt\PublicKey\DiffieHellman

Parameters

$number

string

$format

string

Exceptions

\Zend\Crypt\Exception\InvalidArgumentException

Returns

Setter for the value of the public number

setPublicKey(string $number, string $format) : \Zend\Crypt\PublicKey\DiffieHellman

Parameters

$number

string

$format

string

Exceptions

\Zend\Crypt\Exception\InvalidArgumentException

Returns

Set whether to use openssl extension

useOpensslExtension(bool $flag) 

static

Parameters

$flag

bool

Convert number between formats

convert($number, string $inputFormat, string $outputFormat) : string

Parameters

$number

$inputFormat

string

$outputFormat

string

Returns

string

In the event a private number/key has not been set by the user, or generated by ext/openssl, a best attempt will be made to generate a random key.

generatePrivateKey() : string

Having a random number generator installed on linux/bsd is highly recommended! The alternative is not recommended for production unless without any other option.

Returns

string

 Properties

 

Static flag to select whether to use PHP5.3's openssl extension if available.

$useOpenssl : bool

 

$opensslKeyResource

$opensslKeyResource : resource

 

The default generator number.

$generator : string

This number must be greater than 0 but less than the prime number set.

 

BigInteger support object courtesy of Zend\Math

$math : \Zend\Math\BigInteger\Adapter\AdapterInterface

 

Default large prime number; required by the algorithm.

$prime : string

 

A private number set by the local user.

$privateKey : string

It's optional and will be generated if not set.

 

The public key generated by this instance after calling generateKeys().

$publicKey : string

 

The shared secret key resulting from a completed Diffie Hellman exchange

$secretKey : string

 Constants

 

DEFAULT_KEY_SIZE

DEFAULT_KEY_SIZE 

 

Key formats

FORMAT_BINARY 

 

FORMAT_BTWOC

FORMAT_BTWOC 

 

FORMAT_NUMBER

FORMAT_NUMBER