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
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License

 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 = null, string $privateKeyType = self::NUMBER

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

Parameters

$prime

string

$generator

string

$privateKey

string

$privateKeyType

string

Compute the shared secret key based on the public key received from the the second party to this transaction. This should agree to the secret key the second party computes on our own public key.

computeSecretKey(string $publicKey, string $type = self::NUMBER, string $output = self::NUMBER) : mixed

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

$type

string

$output

string

Exceptions

\Zend_Crypt_DiffieHellman_Exception

Returns

mixed

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

generateKeys() : \Zend_Crypt_DiffieHellman

Returns

\Zend_Crypt_DiffieHellman

Getter for the value of the generator number

getGenerator() : string

Exceptions

\Zend_Crypt_DiffieHellman_Exception

Returns

string

Getter for the value of the prime number

getPrime() : string

Exceptions

\Zend_Crypt_DiffieHellman_Exception

Returns

string

Getter for the value of the private number

getPrivateKey(string $type = self::NUMBER) : string

Parameters

$type

string

Returns

string

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

getPublicKey(string $type = self::NUMBER) : string

Parameters

$type

string

Exceptions

\Zend_Crypt_DiffieHellman_Exception

Returns

string

Return the computed shared secret key from the DiffieHellman transaction

getSharedSecretKey(string $type = self::NUMBER) : string

Parameters

$type

string

Exceptions

\Zend_Crypt_DiffieHellman_Exception

Returns

string

Check whether a private key currently exists.

hasPrivateKey() : boolean

Returns

boolean

Setter to pass an extension parameter which is used to create a specific BigInteger instance for a specific extension type.

setBigIntegerMath(string $extension = null) : void

Allows manual setting of the class in case of an extension problem or bug.

Parameters

$extension

string

Setter for the value of the generator number

setGenerator(string $number) : \Zend_Crypt_DiffieHellman

Parameters

$number

string

Exceptions

\Zend_Crypt_DiffieHellman_Exception

Returns

\Zend_Crypt_DiffieHellman

Setter for the value of the prime number

setPrime(string $number) : \Zend_Crypt_DiffieHellman

Parameters

$number

string

Exceptions

\Zend_Crypt_DiffieHellman_Exception

Returns

\Zend_Crypt_DiffieHellman

Setter for the value of the private number

setPrivateKey(string $number, string $type = self::NUMBER) : \Zend_Crypt_DiffieHellman

Parameters

$number

string

$type

string

Exceptions

\Zend_Crypt_DiffieHellman_Exception

Returns

\Zend_Crypt_DiffieHellman

Setter for the value of the public number

setPublicKey(string $number, string $type = self::NUMBER) : \Zend_Crypt_DiffieHellman

Parameters

$number

string

$type

string

Exceptions

\Zend_Crypt_DiffieHellman_Exception

Returns

\Zend_Crypt_DiffieHellman

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. Having a random number generator installed on linux/bsd is highly recommended! The alternative is not recommended for production unless without any other option.

_generatePrivateKey() : string

Returns

string

 Properties

 

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

$useOpenssl : boolean

Default

true
Static
 

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

$_generator : string

Default

null
 

BigInteger support object courtesy of Zend_Crypt_Math

$_math : \Zend_Crypt_Math_BigInteger

Default

null
 

Default large prime number; required by the algorithm.

$_prime : string

Default

null
 

A private number set by the local user. It's optional and will be generated if not set.

$_privateKey : string

Default

null
 

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

$_publicKey : string

Default

null
 

The shared secret key resulting from a completed Diffie Hellman exchange

$_secretKey : string

Default

null

 Constants

 

Constants

BINARY = 'binary' 
 

BTWOC

BTWOC = 'btwoc' 
 

NUMBER

NUMBER = 'number'