PrivateKey
extends DH
in package
uses
PasswordProtected
DH Private Key
Tags
Table of Contents
Constants
- ALGORITHM = 'DH'
- Algorithm Name
Properties
- $base : BigInteger
- DH Base
- $engines : array<string|int, bool>
- Available Engines
- $format : string
- Format of the loaded key
- $hash : Hash
- Hash function
- $one : BigInteger
- Precomputed One
- $prime : BigInteger
- DH prime
- $privateKey : BigInteger
- Private Key
- $publicKey : BigInteger
- Public Key
- $zero : BigInteger
- Precomputed Zero
- $comment : null|string
- Key Comment
- $hmac : Hash
- HMAC function
- $invisiblePlugins : array<string|int, mixed>
- Invisible plugins
- $password : string|bool
- Password
- $plugins : array<string|int, mixed>
- Supported plugins (lower case)
- $signatureFileFormats : array<string|int, mixed>
- Supported signature formats (original case)
- $signatureFormats : array<string|int, mixed>
- Supported signature formats (lower case)
Methods
- __toString() : string
- __toString() magic method
- addFileFormat() : bool
- Add a fileformat plugin
- computeSecret() : mixed
- Compute Shared Secret
- createKey() : PrivateKey
- Create public / private key pair.
- createParameters() : DH|bool
- Create DH parameters
- getComment() : null|string
- Returns the key's comment
- getHash() : mixed
- Returns the hash algorithm currently being used
- getLoadedFormat() : mixed
- Returns the format of the loaded key.
- getParameters() : mixed
- Returns the parameters
- getPublicKey() : PublicKey
- Returns the public key
- getSupportedKeyFormats() : array<string|int, mixed>
- Returns a list of supported formats.
- load() : AsymmetricKey
- Load the key
- loadFormat() : AsymmetricKey
- Load the key, assuming a specific format
- loadParameters() : AsymmetricKey
- Loads parameters
- loadParametersFormat() : AsymmetricKey
- Loads parameters
- loadPrivateKey() : PrivateKey
- Loads a private key
- loadPrivateKeyFormat() : PrivateKey
- Loads a private key
- loadPublicKey() : PublicKey
- Loads a public key
- loadPublicKeyFormat() : PublicKey
- Loads a public key
- toString() : string
- Returns the private key
- useBestEngine() : mixed
- Tests engine validity
- useInternalEngine() : mixed
- Flag to use internal engine only (useful for unit testing)
- withHash() : mixed
- Determines which hashing function should be used
- withPassword() : mixed
- Sets the password
- __construct() : mixed
- The constructor
- bits2int() : BigInteger
- Bit String to Integer
- computek() : string
- Compute the pseudorandom k for signature generation, using the process specified for deterministic DSA.
- initialize_static_variables() : mixed
- Initialize static variables
- onLoad() : bool
- OnLoad Handler
- validatePlugin() : mixed
- Validate Plugin
- bits2octets() : string
- Bit String to Octet String
- int2octets() : string
- Integer to Octet String
- loadPlugins() : mixed
- Load Plugins
Constants
ALGORITHM
Algorithm Name
public
string
ALGORITHM
= 'DH'
Tags
Properties
$base
DH Base
protected
BigInteger
$base
Prime divisor of p-1
Tags
$engines
Available Engines
protected
static array<string|int, bool>
$engines
= []
Tags
$format
Format of the loaded key
protected
string
$format
Tags
$hash
Hash function
protected
Hash
$hash
Tags
$one
Precomputed One
protected
static BigInteger
$one
Tags
$prime
DH prime
protected
BigInteger
$prime
Tags
$privateKey
Private Key
protected
BigInteger
$privateKey
Tags
$publicKey
Public Key
protected
BigInteger
$publicKey
Tags
$zero
Precomputed Zero
protected
static BigInteger
$zero
Tags
$comment
Key Comment
private
null|string
$comment
Tags
$hmac
HMAC function
private
Hash
$hmac
Tags
$invisiblePlugins
Invisible plugins
private
static array<string|int, mixed>
$invisiblePlugins
= []
Tags
$password
Password
private
string|bool
$password
= false
$plugins
Supported plugins (lower case)
private
static array<string|int, mixed>
$plugins
= []
Tags
$signatureFileFormats
Supported signature formats (original case)
private
static array<string|int, mixed>
$signatureFileFormats
= []
Tags
$signatureFormats
Supported signature formats (lower case)
private
static array<string|int, mixed>
$signatureFormats
= []
Tags
Methods
__toString()
__toString() magic method
public
__toString() : string
Return values
stringaddFileFormat()
Add a fileformat plugin
public
static addFileFormat(string $fullname) : bool
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
- $fullname : string
Tags
Return values
boolcomputeSecret()
Compute Shared Secret
public
static computeSecret(PrivateKey|EC $private, PublicKey|BigInteger|string $public) : mixed
Parameters
- $private : PrivateKey|EC
- $public : PublicKey|BigInteger|string
Tags
createKey()
Create public / private key pair.
public
static createKey(Parameters $params[, int $length = 0 ]) : PrivateKey
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
- $params : Parameters
- $length : int = 0
-
optional
Tags
Return values
PrivateKeycreateParameters()
Create DH parameters
public
static createParameters(mixed ...$args) : DH|bool
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 : mixed
Tags
Return values
DH|boolgetComment()
Returns the key's comment
public
getComment() : null|string
Not all key formats support comments. If you want to set a comment use toString()
Tags
Return values
null|stringgetHash()
Returns the hash algorithm currently being used
public
getHash() : mixed
Tags
getLoadedFormat()
Returns the format of the loaded key.
public
getLoadedFormat() : mixed
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.
Tags
getParameters()
Returns the parameters
public
getParameters() : mixed
A public / private key is only returned if the currently loaded "key" contains an x or y value.
Tags
getPublicKey()
Returns the public key
public
getPublicKey() : PublicKey
Tags
Return values
PublicKeygetSupportedKeyFormats()
Returns a list of supported formats.
public
static getSupportedKeyFormats() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>load()
Load the key
public
static load(string $key[, string $password = false ]) : AsymmetricKey
Parameters
- $key : string
- $password : string = false
-
optional
Return values
AsymmetricKeyloadFormat()
Load the key, assuming a specific format
public
static loadFormat(string $type, string $key[, string $password = false ]) : AsymmetricKey
Parameters
- $type : string
- $key : string
- $password : string = false
-
optional
Return values
AsymmetricKeyloadParameters()
Loads parameters
public
loadParameters(string|array<string|int, mixed> $key) : AsymmetricKey
Parameters
- $key : string|array<string|int, mixed>
Tags
Return values
AsymmetricKeyloadParametersFormat()
Loads parameters
public
loadParametersFormat(string $type, string|array<string|int, mixed> $key) : AsymmetricKey
Parameters
- $type : string
- $key : string|array<string|int, mixed>
Tags
Return values
AsymmetricKeyloadPrivateKey()
Loads a private key
public
loadPrivateKey(string|array<string|int, mixed> $key[, string $password = '' ]) : PrivateKey
Parameters
- $key : string|array<string|int, mixed>
- $password : string = ''
-
optional
Tags
Return values
PrivateKeyloadPrivateKeyFormat()
Loads a private key
public
loadPrivateKeyFormat(string $type, string $key[, string $password = false ]) : PrivateKey
Parameters
- $type : string
- $key : string
- $password : string = false
-
optional
Tags
Return values
PrivateKeyloadPublicKey()
Loads a public key
public
loadPublicKey(string|array<string|int, mixed> $key) : PublicKey
Parameters
- $key : string|array<string|int, mixed>
Tags
Return values
PublicKeyloadPublicKeyFormat()
Loads a public key
public
loadPublicKeyFormat(string $type, string $key) : PublicKey
Parameters
- $type : string
- $key : string
Tags
Return values
PublicKeytoString()
Returns the private key
public
toString(string $type[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $type : string
- $options : array<string|int, mixed> = []
-
optional
Return values
stringuseBestEngine()
Tests engine validity
public
static useBestEngine() : mixed
Tags
useInternalEngine()
Flag to use internal engine only (useful for unit testing)
public
static useInternalEngine() : mixed
Tags
withHash()
Determines which hashing function should be used
public
withHash(string $hash) : mixed
Parameters
- $hash : string
Tags
withPassword()
Sets the password
public
withPassword([string|bool $password = false ]) : mixed
Private keys can be encrypted with a password. To unset the password, pass in the empty string or false. Or rather, pass in $password such that empty($password) && !is_string($password) is true.
Parameters
- $password : string|bool = false
Tags
__construct()
The constructor
protected
__construct() : mixed
bits2int()
Bit String to Integer
protected
bits2int(string $in) : BigInteger
Parameters
- $in : string
Tags
Return values
BigIntegercomputek()
Compute the pseudorandom k for signature generation, using the process specified for deterministic DSA.
protected
computek(string $h1) : string
Parameters
- $h1 : string
Tags
Return values
stringinitialize_static_variables()
Initialize static variables
protected
static initialize_static_variables() : mixed
onLoad()
OnLoad Handler
protected
static onLoad(array<string|int, mixed> $components) : bool
Parameters
- $components : array<string|int, mixed>
Tags
Return values
boolvalidatePlugin()
Validate Plugin
protected
static validatePlugin(string $format, string $type[, string $method = NULL ]) : mixed
Parameters
- $format : string
- $type : string
- $method : string = NULL
-
optional
Tags
bits2octets()
Bit String to Octet String
private
bits2octets(string $in) : string
Parameters
- $in : string
Tags
Return values
stringint2octets()
Integer to Octet String
private
int2octets(BigInteger $v) : string
Parameters
- $v : BigInteger
Tags
Return values
stringloadPlugins()
Load Plugins
private
static loadPlugins(string $format) : mixed
Parameters
- $format : string