class PublicKey extends DH (View source)

DH Public Key

Traits

Fingerprint Trait for Private Keys

Constants

ALGORITHM

Algorithm Name

Properties

static protected BigInteger $zero Precomputed Zero from  AsymmetricKey
static protected BigInteger $one Precomputed One from  AsymmetricKey
protected string $format Format of the loaded key from  AsymmetricKey
protected Hash $hash Hash function from  AsymmetricKey
static protected bool[] $engines Available Engines from  AsymmetricKey
protected BigInteger $prime DH prime from  DH
protected BigInteger $base DH Base from  DH

Methods

__construct()

The constructor

static 
initialize_static_variables()

Initialize static variables

static AsymmetricKey
load(string $key, string $password = false)

Load the key

from  DH
PrivateKey
loadPrivateKey(string|array $key, string $password = '')

Loads a private key

PublicKey
loadPublicKey(string|array $key)

Loads a public key

AsymmetricKey
loadParameters(string|array $key)

Loads parameters

static AsymmetricKey
loadFormat(string $type, string $key, string $password = false)

Load the key, assuming a specific format

PrivateKey
loadPrivateKeyFormat(string $type, string $key, string $password = false)

Loads a private key

PublicKey
loadPublicKeyFormat(string $type, string $key)

Loads a public key

AsymmetricKey
loadParametersFormat(string $type, string|array $key)

Loads parameters

static mixed
validatePlugin(string $format, string $type, string $method = NULL)

Validate Plugin

static array
getSupportedKeyFormats()

Returns a list of supported formats.

static bool
addFileFormat(string $fullname)

Add a fileformat plugin

mixed
getLoadedFormat()

Returns the format of the loaded key.

null|string
getComment()

Returns the key's comment

static 
useBestEngine()

Tests engine validity

static 
useInternalEngine()

Flag to use internal engine only (useful for unit testing)

string
__toString()

__toString() magic method

withHash(string $hash)

Determines which hashing function should be used

from  DH
getHash()

Returns the hash algorithm currently being used

from  DH
string
computek(string $h1)

Compute the pseudorandom k for signature generation, using the process specified for deterministic DSA.

bits2int(string $in)

Bit String to Integer

static DH|bool
createParameters(...$args)

Create DH parameters

from  DH
static PrivateKey
createKey(Parameters $params, int $length = 0)

Create public / private key pair.

from  DH
static mixed
computeSecret(PrivateKey|EC $private, PublicKey|BigInteger|string $public)

Compute Shared Secret

from  DH
static bool
onLoad(array $components)

OnLoad Handler

from  DH
mixed
getParameters()

Returns the parameters

from  DH
mixed
getFingerprint(string $algorithm = 'md5')

Returns the public key's fingerprint

string
toString(string $type, array $options = [])

Returns the public key

toBigInteger()

Returns the public key as a BigInteger

Details

protected __construct()

The constructor

static protected initialize_static_variables()

Initialize static variables

static AsymmetricKey load(string $key, string $password = false)

Load the key

Parameters

string $key
string $password optional

Return Value

AsymmetricKey

PrivateKey loadPrivateKey(string|array $key, string $password = '')

Loads a private key

Parameters

string|array $key
string $password optional

Return Value

PrivateKey

PublicKey loadPublicKey(string|array $key)

Loads a public key

Parameters

string|array $key

Return Value

PublicKey

AsymmetricKey loadParameters(string|array $key)

Loads parameters

Parameters

string|array $key

Return Value

AsymmetricKey

static AsymmetricKey loadFormat(string $type, string $key, string $password = false)

Load the key, assuming a specific format

Parameters

string $type
string $key
string $password optional

Return Value

AsymmetricKey

PrivateKey loadPrivateKeyFormat(string $type, string $key, string $password = false)

Loads a private key

Parameters

string $type
string $key
string $password optional

Return Value

PrivateKey

PublicKey loadPublicKeyFormat(string $type, string $key)

Loads a public key

Parameters

string $type
string $key

Return Value

PublicKey

AsymmetricKey loadParametersFormat(string $type, string|array $key)

Loads parameters

Parameters

string $type
string|array $key

Return Value

AsymmetricKey

static protected mixed validatePlugin(string $format, string $type, string $method = NULL)

Validate Plugin

Parameters

string $format
string $type
string $method optional

Return Value

mixed

static array getSupportedKeyFormats()

Returns a list of supported formats.

Return Value

array

static bool addFileFormat(string $fullname)

Add a fileformat plugin

The plugin needs to either already be loaded or be auto-loadable. Loading a plugin whose shortname overwrite an existing shortname will overwrite the old plugin.

Parameters

string $fullname

Return Value

bool

See also

\self::load()

mixed getLoadedFormat()

Returns the format of the loaded key.

If the key that was loaded wasn't in a valid or if the key was auto-generated with RSA::createKey() then this will throw an exception.

Return Value

mixed

See also

\self::load()

null|string getComment()

Returns the key's comment

Not all key formats support comments. If you want to set a comment use toString()

Return Value

null|string

static useBestEngine()

Tests engine validity

static useInternalEngine()

Flag to use internal engine only (useful for unit testing)

string __toString()

__toString() magic method

Return Value

string

withHash(string $hash)

Determines which hashing function should be used

Parameters

string $hash

getHash()

Returns the hash algorithm currently being used

protected string computek(string $h1)

Compute the pseudorandom k for signature generation, using the process specified for deterministic DSA.

Parameters

string $h1

Return Value

string

protected BigInteger bits2int(string $in)

Bit String to Integer

Parameters

string $in

Return Value

BigInteger

static DH|bool createParameters(...$args)

Create DH parameters

This method is a bit polymorphic. It can take any of the following: - two BigInteger's (prime and base) - an integer representing the size of the prime in bits (the base is assumed to be 2) - a string (eg. diffie-hellman-group14-sha1)

Parameters

...$args

Return Value

DH|bool

static PrivateKey createKey(Parameters $params, int $length = 0)

Create public / private key pair.

The rationale for the second parameter is described in http://tools.ietf.org/html/rfc4419#section-6.2 :

"To increase the speed of the key exchange, both client and server may reduce the size of their private exponents. It should be at least twice as long as the key material that is generated from the shared secret. For more details, see the paper by van Oorschot and Wiener [VAN-OORSCHOT]."

$length is in bits

Parameters

Parameters $params
int $length optional

Return Value

PrivateKey

static mixed computeSecret(PrivateKey|EC $private, PublicKey|BigInteger|string $public)

Compute Shared Secret

Parameters

PrivateKey|EC $private
PublicKey|BigInteger|string $public

Return Value

mixed

static protected bool onLoad(array $components)

OnLoad Handler

Parameters

array $components

Return Value

bool

mixed getParameters()

Returns the parameters

A public / private key is only returned if the currently loaded "key" contains an x or y value.

Return Value

mixed

See also

\self::getPublicKey()

mixed getFingerprint(string $algorithm = 'md5')

Returns the public key's fingerprint

The public key's fingerprint is returned, which is equivalent to running ssh-keygen -lf rsa.pub. If there is no public key currently loaded, false is returned. Example output (md5): "c1:b1:30:29:d7:b8:de:6c:97:77:10:d7:46:41:63:87" (as specified by RFC 4716)

Parameters

string $algorithm The hashing algorithm to be used. Valid options are 'md5' and 'sha256'. False is returned for invalid values.

Return Value

mixed

string toString(string $type, array $options = [])

Returns the public key

Parameters

string $type
array $options optional

Return Value

string

BigInteger toBigInteger()

Returns the public key as a BigInteger

Return Value

BigInteger