1495. Class

1495.1. Zend\Crypt\PublicKey\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.

1495.1.1. Methods

1495.1.1.1. __construct

__construct()

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
  • string
  • string
  • string

1495.1.1.2. useOpensslExtension

useOpensslExtension()

Set whether to use openssl extension

Parameters:bool

1495.1.1.3. generateKeys

generateKeys()

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

Return type:DiffieHellman
Throws :ZendCryptExceptionRuntimeException

1495.1.1.4. setPublicKey

setPublicKey()

Setter for the value of the public number

Parameters:
  • string
  • string
Return type:

DiffieHellman

Throws :

ZendCryptExceptionInvalidArgumentException

1495.1.1.5. getPublicKey

getPublicKey()

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

Parameters:string
Return type:string
Throws :ZendCryptExceptionInvalidArgumentException

1495.1.1.6. computeSecretKey

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. 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
  • string
  • string
Return type:

string

Throws :

ZendCryptExceptionInvalidArgumentException

Throws :

ZendCryptExceptionRuntimeException

1495.1.1.7. getSharedSecretKey

getSharedSecretKey()

Return the computed shared secret key from the DiffieHellman transaction

Parameters:string
Return type:string
Throws :ZendCryptExceptionInvalidArgumentException

1495.1.1.8. setPrime

setPrime()

Setter for the value of the prime number

Parameters:string
Return type:DiffieHellman
Throws :ZendCryptExceptionInvalidArgumentException

1495.1.1.9. getPrime

getPrime()

Getter for the value of the prime number

Parameters:string
Return type:string
Throws :ZendCryptExceptionInvalidArgumentException

1495.1.1.10. setGenerator

setGenerator()

Setter for the value of the generator number

Parameters:string
Return type:DiffieHellman
Throws :ZendCryptExceptionInvalidArgumentException

1495.1.1.11. getGenerator

getGenerator()

Getter for the value of the generator number

Parameters:string
Return type:string
Throws :ZendCryptExceptionInvalidArgumentException

1495.1.1.12. setPrivateKey

setPrivateKey()

Setter for the value of the private number

Parameters:
  • string
  • string
Return type:

DiffieHellman

Throws :

ZendCryptExceptionInvalidArgumentException

1495.1.1.13. getPrivateKey

getPrivateKey()

Getter for the value of the private number

Parameters:string
Return type:string

1495.1.1.14. hasPrivateKey

hasPrivateKey()

Check whether a private key currently exists.

Return type:bool

1495.1.1.15. convert

convert()

Convert number between formats

Parameters:
  • $number
  • string
  • string
Return type:

string

1495.1.1.16. generatePrivateKey

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.

Return type:string

1495.1.2. Constants

1495.1.2.1. DEFAULT_KEY_SIZE

1495.1.2.2. FORMAT_BINARY

Key formats

1495.1.2.3. FORMAT_NUMBER

1495.1.2.4. FORMAT_BTWOC