Definition at line 33 of file DiffieHellman.php.
◆ __construct()
__construct |
( |
|
$prime, |
|
|
|
$generator, |
|
|
|
$privateKey = null , |
|
|
|
$privateKeyType = self::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.
- Parameters
-
string | $prime | |
string | $generator | |
string | $privateKey | |
string | $privateKeyType | |
Definition at line 106 of file DiffieHellman.php.
110 if ($privateKey !==
null) {
setBigIntegerMath($extension=null)
setPrivateKey($number, $type=self::NUMBER)
◆ _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. 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
Definition at line 382 of file DiffieHellman.php.
◆ computeSecretKey()
computeSecretKey |
( |
|
$publicKey, |
|
|
|
$type = self::NUMBER , |
|
|
|
$output = self::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.
- Parameters
-
string | $publicKey | |
string | $type | |
string | $output | |
- Exceptions
-
- Returns
- mixed
Definition at line 203 of file DiffieHellman.php.
205 if (
$type == self::BINARY) {
206 $publicKey = $this->_math->fromBinary($publicKey);
208 if (!preg_match(
"/^\d+$/", $publicKey)) {
209 #require_once('Zend/Crypt/DiffieHellman/Exception.php'); 212 if (
function_exists(
'openssl_dh_compute_key') && self::$useOpenssl !==
false) {
213 $this->_secretKey = openssl_dh_compute_key($publicKey, $this->
getPublicKey());
getPrivateKey($type=self::NUMBER)
getPublicKey($type=self::NUMBER)
getSharedSecretKey($type=self::NUMBER)
◆ generateKeys()
Generate own public key. If a private number has not already been set, one will be generated at this stage.
- Returns
- Zend_Crypt_DiffieHellman
Definition at line 122 of file DiffieHellman.php.
124 if (
function_exists(
'openssl_dh_compute_key') && self::$useOpenssl !==
false) {
131 $opensslKeyResource = openssl_pkey_new( array(
'dh' =>
$details) );
132 $data = openssl_pkey_get_details($opensslKeyResource);
getPrivateKey($type=self::NUMBER)
setPrivateKey($number, $type=self::NUMBER)
setPublicKey($number, $type=self::NUMBER)
◆ getGenerator()
Getter for the value of the generator number
- Exceptions
-
- Returns
- string
Definition at line 296 of file DiffieHellman.php.
298 if (!isset($this->_generator)) {
299 #require_once('Zend/Crypt/DiffieHellman/Exception.php'); 302 return $this->_generator;
◆ getPrime()
Getter for the value of the prime number
- Exceptions
-
- Returns
- string
Definition at line 264 of file DiffieHellman.php.
266 if (!isset($this->_prime)) {
267 #require_once('Zend/Crypt/DiffieHellman/Exception.php'); 270 return $this->_prime;
◆ getPrivateKey()
getPrivateKey |
( |
|
$type = self::NUMBER | ) |
|
Getter for the value of the private number
- Parameters
-
- Returns
- string
Definition at line 332 of file DiffieHellman.php.
337 if (
$type == self::BINARY) {
338 return $this->_math->toBinary($this->_privateKey);
340 return $this->_math->btwoc($this->_math->toBinary($this->_privateKey));
342 return $this->_privateKey;
elseif(isset( $params[ 'redirect_parent']))
setPrivateKey($number, $type=self::NUMBER)
◆ getPublicKey()
getPublicKey |
( |
|
$type = self::NUMBER | ) |
|
Returns own public key for communication to the second party to this transaction.
- Parameters
-
- Exceptions
-
- Returns
- string
Definition at line 172 of file DiffieHellman.php.
174 if ($this->_publicKey ===
null) {
175 #require_once 'Zend/Crypt/DiffieHellman/Exception.php'; 178 if (
$type == self::BINARY) {
179 return $this->_math->toBinary($this->_publicKey);
181 return $this->_math->btwoc($this->_math->toBinary($this->_publicKey));
183 return $this->_publicKey;
elseif(isset( $params[ 'redirect_parent']))
◆ getSharedSecretKey()
getSharedSecretKey |
( |
|
$type = self::NUMBER | ) |
|
Return the computed shared secret key from the DiffieHellman transaction
- Parameters
-
- Exceptions
-
- Returns
- string
Definition at line 227 of file DiffieHellman.php.
229 if (!isset($this->_secretKey)) {
230 #require_once('Zend/Crypt/DiffieHellman/Exception.php'); 233 if (
$type == self::BINARY) {
234 return $this->_math->toBinary($this->_secretKey);
236 return $this->_math->btwoc($this->_math->toBinary($this->_secretKey));
238 return $this->_secretKey;
elseif(isset( $params[ 'redirect_parent']))
◆ hasPrivateKey()
Check whether a private key currently exists.
- Returns
- boolean
Definition at line 350 of file DiffieHellman.php.
352 return isset($this->_privateKey);
◆ setBigIntegerMath()
setBigIntegerMath |
( |
|
$extension = null | ) |
|
Setter to pass an extension parameter which is used to create a specific BigInteger instance for a specific extension type. Allows manual setting of the class in case of an extension problem or bug.
- Parameters
-
- Returns
- void
- See also
- Zend_Crypt_Math
Definition at line 364 of file DiffieHellman.php.
369 #require_once 'Zend/Crypt/Math.php';
◆ setGenerator()
◆ setPrime()
◆ setPrivateKey()
setPrivateKey |
( |
|
$number, |
|
|
|
$type = self::NUMBER |
|
) |
| |
Setter for the value of the private number
- Parameters
-
string | $number | |
string | $type | |
- Exceptions
-
- Returns
- Zend_Crypt_DiffieHellman
Definition at line 313 of file DiffieHellman.php.
315 if (
$type == self::BINARY) {
318 if (!preg_match(
"/^\d+$/",
$number)) {
319 #require_once('Zend/Crypt/DiffieHellman/Exception.php'); 322 $this->_privateKey = (string)
$number;
◆ setPublicKey()
setPublicKey |
( |
|
$number, |
|
|
|
$type = self::NUMBER |
|
) |
| |
Setter for the value of the public number
- Parameters
-
string | $number | |
string | $type | |
- Exceptions
-
- Returns
- Zend_Crypt_DiffieHellman
Definition at line 151 of file DiffieHellman.php.
153 if (
$type == self::BINARY) {
156 if (!preg_match(
"/^\d+$/",
$number)) {
157 #require_once('Zend/Crypt/DiffieHellman/Exception.php'); 160 $this->_publicKey = (string)
$number;
◆ $useOpenssl
◆ BINARY
◆ BTWOC
◆ NUMBER
The documentation for this class was generated from the following file: