Class DiffieHellman

Summary

Fully Qualified Name: Zend\Crypt\PublicKey\DiffieHellman

Description

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.

Methods

Name Description Defined By
__construct() Constructor; if set construct the object using the parameter array to set values for Prime, Generator and Private. DiffieHellman
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. DiffieHellman
generateKeys() Generate own public key. If a private number has not already been set, one will be generated at this stage. DiffieHellman
getGenerator() Getter for the value of the generator number DiffieHellman
getPrime() Getter for the value of the prime number DiffieHellman
getPrivateKey() Getter for the value of the private number DiffieHellman
getPublicKey() Returns own public key for communication to the second party to this transaction DiffieHellman
getSharedSecretKey() Return the computed shared secret key from the DiffieHellman transaction DiffieHellman
hasPrivateKey() Check whether a private key currently exists. DiffieHellman
setGenerator() Setter for the value of the generator number DiffieHellman
setPrime() Setter for the value of the prime number DiffieHellman
setPrivateKey() Setter for the value of the private number DiffieHellman
setPublicKey() Setter for the value of the public number DiffieHellman
useOpensslExtension() Set whether to use openssl extension DiffieHellman

Method Details

__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.

Parameter Name Type Description
$prime string
$generator string
$privateKey string
$privateKeyFormat string

Returns:

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.

Parameter Name Type Description
$publicKey string
$publicKeyFormat string
$secretKeyFormat string

Returns: string

generateKeys()

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

Returns: \DiffieHellman Provides a fluent interface

getGenerator()

Getter for the value of the generator number

Parameter Name Type Description
$format string

Returns: string

getPrime()

Getter for the value of the prime number

Parameter Name Type Description
$format string

Returns: string

getPrivateKey()

Getter for the value of the private number

Parameter Name Type Description
$format string

Returns: string

getPublicKey()

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

Parameter Name Type Description
$format string

Returns: string

getSharedSecretKey()

Return the computed shared secret key from the DiffieHellman transaction

Parameter Name Type Description
$format string

Returns: string

hasPrivateKey()

Check whether a private key currently exists.

Returns: bool

setGenerator()

Setter for the value of the generator number

Parameter Name Type Description
$number string

Returns: \DiffieHellman Provides a fluent interface

setPrime()

Setter for the value of the prime number

Parameter Name Type Description
$number string

Returns: \DiffieHellman Provides a fluent interface

setPrivateKey()

Setter for the value of the private number

Parameter Name Type Description
$number string
$format string

Returns: \DiffieHellman Provides a fluent interface

setPublicKey()

Setter for the value of the public number

Parameter Name Type Description
$number string
$format string

Returns: \DiffieHellman Provides a fluent interface

useOpensslExtension()

Set whether to use openssl extension

Parameter Name Type Description
$flag bool

Returns:

Top