Zend Framework
3.0
|
PHP implementation of the Diffie-Hellman public key encryption algorithm. More...
Public Member Functions | |
__construct ($prime, $generator, $privateKey=null, $privateKeyFormat=self::FORMAT_NUMBER) | |
Constructor; if set construct the object using the parameter array to set values for Prime, Generator and Private. | |
generateKeys () | |
Generate own public key. | |
setPublicKey ($number, $format=self::FORMAT_NUMBER) | |
Setter for the value of the public number. | |
getPublicKey ($format=self::FORMAT_NUMBER) | |
Returns own public key for communication to the second party to this transaction. | |
computeSecretKey ($publicKey, $publicKeyFormat=self::FORMAT_NUMBER, $secretKeyFormat=self::FORMAT_NUMBER) | |
Compute the shared secret key based on the public key received from the the second party to this transaction. | |
getSharedSecretKey ($format=self::FORMAT_NUMBER) | |
Return the computed shared secret key from the DiffieHellman transaction. | |
setPrime ($number) | |
Setter for the value of the prime number. | |
getPrime ($format=self::FORMAT_NUMBER) | |
Getter for the value of the prime number. | |
setGenerator ($number) | |
Setter for the value of the generator number. | |
getGenerator ($format=self::FORMAT_NUMBER) | |
Getter for the value of the generator number. | |
setPrivateKey ($number, $format=self::FORMAT_NUMBER) | |
Setter for the value of the private number. | |
getPrivateKey ($format=self::FORMAT_NUMBER) | |
Getter for the value of the private number. | |
hasPrivateKey () | |
Check whether a private key currently exists. | |
Static Public Member Functions | |
static | useOpensslExtension ($flag=true) |
Set whether to use openssl extension. | |
Public Attributes | |
const | DEFAULT_KEY_SIZE = 2048 |
const | FORMAT_BINARY = 'binary' |
Key formats. | |
const | FORMAT_NUMBER = 'number' |
const | FORMAT_BTWOC = 'btwoc' |
Static Public Attributes | |
static | $useOpenssl = true |
Protected Member Functions | |
convert ($number, $inputFormat=self::FORMAT_NUMBER, $outputFormat=self::FORMAT_BINARY) | |
Convert number between formats. | |
generatePrivateKey () | |
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. | |
Protected Attributes | |
$opensslKeyResource = null | |
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.
__construct | ( | $prime, | |
$generator, | |||
$privateKey = null , |
|||
$privateKeyFormat = self::FORMAT_NUMBER |
|||
) |
Constructor; if set construct the object using the parameter array to set values for Prime, Generator and Private.
If a Private Key is not set, one will be generated at random.
string | $prime | |
string | $generator | |
string | $privateKey | |
string | $privateKeyFormat |
computeSecretKey | ( | $publicKey, | |
$publicKeyFormat = self::FORMAT_NUMBER , |
|||
$secretKeyFormat = self::FORMAT_NUMBER |
|||
) |
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. 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.
string | $publicKey | |
string | $publicKeyFormat | |
string | $secretKeyFormat |
\Zend\Crypt\Exception\InvalidArgumentException | |
\Zend\Crypt\Exception\RuntimeException |
|
protected |
Convert number between formats.
string | $number | |
string | $inputFormat | |
string | $outputFormat |
generateKeys | ( | ) |
Generate own public key.
If a private number has not already been set, one will be generated at this stage.
\Zend\Crypt\Exception\RuntimeException |
|
protected |
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.
getGenerator | ( | $format = self::FORMAT_NUMBER | ) |
Getter for the value of the generator number.
string | $format |
\Zend\Crypt\Exception\InvalidArgumentException |
getPrime | ( | $format = self::FORMAT_NUMBER | ) |
Getter for the value of the prime number.
string | $format |
\Zend\Crypt\Exception\InvalidArgumentException |
getPrivateKey | ( | $format = self::FORMAT_NUMBER | ) |
Getter for the value of the private number.
string | $format |
getPublicKey | ( | $format = self::FORMAT_NUMBER | ) |
Returns own public key for communication to the second party to this transaction.
string | $format |
\Zend\Crypt\Exception\InvalidArgumentException |
getSharedSecretKey | ( | $format = self::FORMAT_NUMBER | ) |
Return the computed shared secret key from the DiffieHellman transaction.
string | $format |
\Zend\Crypt\Exception\InvalidArgumentException |
hasPrivateKey | ( | ) |
Check whether a private key currently exists.
setGenerator | ( | $number | ) |
Setter for the value of the generator number.
string | $number |
\Zend\Crypt\Exception\InvalidArgumentException |
setPrime | ( | $number | ) |
Setter for the value of the prime number.
string | $number |
\Zend\Crypt\Exception\InvalidArgumentException |
setPrivateKey | ( | $number, | |
$format = self::FORMAT_NUMBER |
|||
) |
Setter for the value of the private number.
string | $number | |
string | $format |
\Zend\Crypt\Exception\InvalidArgumentException |
setPublicKey | ( | $number, | |
$format = self::FORMAT_NUMBER |
|||
) |
Setter for the value of the public number.
string | $number | |
string | $format |
\Zend\Crypt\Exception\InvalidArgumentException |
|
static |
Set whether to use openssl extension.
bool | $flag |
|
protected |
|
static |
const DEFAULT_KEY_SIZE = 2048 |
const FORMAT_BINARY = 'binary' |
Key formats.
const FORMAT_BTWOC = 'btwoc' |
const FORMAT_NUMBER = 'number' |