\Zend_Crypt_DiffieHellman
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.
- Copyright: Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
- License: http://framework.zend.com/license/new-bsd New BSD License
Synopsis
class Zend_Crypt_DiffieHellman
{
- // constants
- const BINARY = 'binary';
- const NUMBER = 'number';
- const BTWOC = 'btwoc';
- // members
- public static boolean $useOpenssl = true;
- private $_prime = NULL;
- private $_generator = NULL;
- private $_privateKey = NULL;
- private Zend_Crypt_Math_BigInteger $_math = NULL;
- private $_publicKey = NULL;
- private $_secretKey = NULL;
- // methods
- public void __construct()
- public Zend_Crypt_DiffieHellman generateKeys()
- public Zend_Crypt_DiffieHellman setPublicKey()
- public string getPublicKey()
- public mixed computeSecretKey()
- public string getSharedSecretKey()
- public Zend_Crypt_DiffieHellman setPrime()
- public string getPrime()
- public Zend_Crypt_DiffieHellman setGenerator()
- public string getGenerator()
- public Zend_Crypt_DiffieHellman setPrivateKey()
- public string getPrivateKey()
- public boolean hasPrivateKey()
- public void setBigIntegerMath()
- protected string _generatePrivateKey()
Constants
Name | Value |
---|---|
BINARY | 'binary' |
NUMBER | 'number' |
BTWOC | 'btwoc' |
Members
private
- $_generator
—
string
The default generator number. This number must be greater than 0 but less than the prime number set. - $_math
—
Zend_Crypt_Math_BigInteger
BigInteger support object courtesy of Zend_Crypt_Math - $_prime
—
string
Default large prime number; required by the algorithm. - $_privateKey
—
string
A private number set by the local user. It's optional and will be generated if not set. - $_publicKey
—
string
The public key generated by this instance after calling generateKeys(). - $_secretKey
—
string
The shared secret key resulting from a completed Diffie Hellman exchange
public
- $useOpenssl
—
boolean
Static flag to select whether to use PHP5.3's openssl extension if available.
Methods
protected
- _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.
public
- __construct() — Constructor; if set construct the object using the parameter array to set values for Prime, Generator and Private.
- computeSecretKey() — 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.
- generateKeys() — Generate own public key. If a private number has not already been set, one will be generated at this stage.
- getGenerator() — Getter for the value of the generator number
- getPrime() — Getter for the value of the prime number
- getPrivateKey() — Getter for the value of the private number
- getPublicKey() — Returns own public key for communication to the second party to this transaction.
- hasPrivateKey() — Check whether a private key currently exists.
- setBigIntegerMath() — Setter to pass an extension parameter which is used to create a specific BigInteger instance for a specific extension type.
- setGenerator() — Setter for the value of the generator number
- setPrime() — Setter for the value of the prime number
- setPrivateKey() — Setter for the value of the private number
- setPublicKey() — Setter for the value of the public number