Documentation

PrivateKey extends EC
in package
implements PrivateKey uses PasswordProtected

EC Private Key

Tags
author

Jim Wigginton terrafrost@php.net

access

public

Table of Contents

Interfaces

PrivateKey
PrivateKey interface

Constants

ALGORITHM  = 'EC'
Algorithm Name

Properties

$context  : string
Context
$curve  : Base
Curve
$dA  : object
Private Key dA
$engines  : array<string|int, bool>
Available Engines
$format  : string
Signature Format
$hash  : Hash
Hash function
$one  : BigInteger
Precomputed One
$q  : BigInteger
Curve Order
$QA  : array<string|int, object>
Public Key QA
$shortFormat  : string
Signature Format (Short)
$x  : BigInteger
Alias for the private key
$zero  : BigInteger
Precomputed Zero
$comment  : null|string
Key Comment
$curveName  : string
Curve Name
$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
createKey()  : PrivateKey
Create public / private key pair.
getComment()  : null|string
Returns the key's comment
getContext()  : mixed
Returns the signature format currently being used
getCurve()  : string|array<string|int, mixed>
Returns the curve
getEncodedCoordinates()  : string
Returns the public key coordinates as a string
getEngine()  : string
Returns the current engine being used
getHash()  : mixed
Returns the hash algorithm currently being used
getLength()  : int
Returns the key size
getLoadedFormat()  : mixed
Returns the format of the loaded key.
getParameters()  : mixed
Returns the parameters
getPublicKey()  : mixed
Returns the public key
getSignatureFormat()  : mixed
Returns the signature format currently being used
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
multiply()  : string
Multiplies an encoded point by the private key
sign()  : mixed
Create a signature
toString()  : string
Returns the private key
useBestEngine()  : mixed
Tests engine validity
useInternalEngine()  : mixed
Flag to use internal engine only (useful for unit testing)
withContext()  : mixed
Sets the context
withHash()  : mixed
Determines which hashing function should be used
withPassword()  : mixed
Sets the password
withSignatureFormat()  : mixed
Determines the signature padding mode
__construct()  : mixed
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 = 'EC'
Tags
access

private

Properties

$context

Context

protected string $context

$dA

Private Key dA

protected object $dA

sign() converts this to a BigInteger so one might wonder why this is a FiniteFieldInteger instead of a BigInteger. That's because a FiniteFieldInteger, when converted to a byte string, is null padded by a certain amount whereas a BigInteger isn't.

$engines

Available Engines

protected static array<string|int, bool> $engines = []
Tags
access

private

$format

Signature Format

protected string $format
Tags
access

private

$q

Curve Order

protected BigInteger $q

Used for deterministic ECDSA

$QA

Public Key QA

protected array<string|int, object> $QA

$shortFormat

Signature Format (Short)

protected string $shortFormat
Tags
access

private

$x

Alias for the private key

protected BigInteger $x

Used for deterministic ECDSA. AsymmetricKey expects $x. I don't like x because with x you have x * the base point yielding an (x, y)-coordinate that is the public key. But the x is different depending on which side of the equal sign you're on. It's less ambiguous if you do dA * base point = (x, y)-coordinate.

$comment

Key Comment

private null|string $comment
Tags
access

private

$curveName

Curve Name

private string $curveName

$invisiblePlugins

Invisible plugins

private static array<string|int, mixed> $invisiblePlugins = []
Tags
see
self::initialize_static_variables()
access

private

$plugins

Supported plugins (lower case)

private static array<string|int, mixed> $plugins = []
Tags
see
self::initialize_static_variables()
access

private

$signatureFileFormats

Supported signature formats (original case)

private static array<string|int, mixed> $signatureFileFormats = []
Tags
see
self::initialize_static_variables()
access

private

$signatureFormats

Supported signature formats (lower case)

private static array<string|int, mixed> $signatureFormats = []
Tags
see
self::initialize_static_variables()
access

private

Methods

__toString()

__toString() magic method

public __toString() : string
Return values
string

addFileFormat()

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
see
self::load()
access

public

Return values
bool

createKey()

Create public / private key pair.

public static createKey(string $curve) : PrivateKey
Parameters
$curve : string
Tags
access

public

Return values
PrivateKey

getComment()

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
access

public

Return values
null|string

getContext()

Returns the signature format currently being used

public getContext() : mixed
Tags
access

public

getCurve()

Returns the curve

public getCurve() : string|array<string|int, mixed>

Returns a string if it's a named curve, an array if not

Tags
access

public

Return values
string|array<string|int, mixed>

getEncodedCoordinates()

Returns the public key coordinates as a string

public getEncodedCoordinates() : string

Used by ECDH

Return values
string

getEngine()

Returns the current engine being used

public getEngine() : string
Tags
see
self::useInternalEngine()
see
self::useBestEngine()
access

public

Return values
string

getHash()

Returns the hash algorithm currently being used

public getHash() : mixed
Tags
access

public

getLength()

Returns the key size

public getLength() : int

Quoting https://tools.ietf.org/html/rfc5656#section-2,

"The size of a set of elliptic curve domain parameters on a prime curve is defined as the number of bits in the binary representation of the field order, commonly denoted by p. Size on a characteristic-2 curve is defined as the number of bits in the binary representation of the field, commonly denoted by m. A set of elliptic curve domain parameters defines a group of order n generated by a base point P"

Tags
access

public

Return values
int

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
see
self::load()
access

public

getParameters()

Returns the parameters

public getParameters([string $type = 'PKCS1' ]) : mixed
Parameters
$type : string = 'PKCS1'

optional

Tags
see
self::getPublicKey()
access

public

getPublicKey()

Returns the public key

public getPublicKey() : mixed
Tags
see
self::getPrivateKey()
access

public

getSignatureFormat()

Returns the signature format currently being used

public getSignatureFormat() : mixed
Tags
access

public

getSupportedKeyFormats()

Returns a list of supported formats.

public static getSupportedKeyFormats() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

loadFormat()

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
AsymmetricKey

loadParameters()

Loads parameters

public loadParameters(string|array<string|int, mixed> $key) : AsymmetricKey
Parameters
$key : string|array<string|int, mixed>
Tags
access

public

Return values
AsymmetricKey

loadParametersFormat()

Loads parameters

public loadParametersFormat(string $type, string|array<string|int, mixed> $key) : AsymmetricKey
Parameters
$type : string
$key : string|array<string|int, mixed>
Tags
access

public

Return values
AsymmetricKey

loadPrivateKey()

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
access

public

Return values
PrivateKey

loadPrivateKeyFormat()

Loads a private key

public loadPrivateKeyFormat(string $type, string $key[, string $password = false ]) : PrivateKey
Parameters
$type : string
$key : string
$password : string = false

optional

Tags
access

public

Return values
PrivateKey

loadPublicKey()

Loads a public key

public loadPublicKey(string|array<string|int, mixed> $key) : PublicKey
Parameters
$key : string|array<string|int, mixed>
Tags
access

public

Return values
PublicKey

loadPublicKeyFormat()

Loads a public key

public loadPublicKeyFormat(string $type, string $key) : PublicKey
Parameters
$type : string
$key : string
Tags
access

public

Return values
PublicKey

multiply()

Multiplies an encoded point by the private key

public multiply(string $coordinates) : string

Used by ECDH

Parameters
$coordinates : string
Return values
string

sign()

Create a signature

public sign(string $message) : mixed
Parameters
$message : string
Tags
see
self::verify()
access

public

toString()

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
string

useBestEngine()

Tests engine validity

public static useBestEngine() : mixed
Tags
access

public

useInternalEngine()

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

public static useInternalEngine() : mixed
Tags
access

public

withContext()

Sets the context

public withContext([string $context = null ]) : mixed

Used by Ed25519 / Ed448.

Parameters
$context : string = null

optional

Tags
see
self::sign()
see
self::verify()
access

public

withHash()

Determines which hashing function should be used

public withHash(string $hash) : mixed
Parameters
$hash : string
Tags
access

public

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
see
self::createKey()
see
self::load()
access

public

withSignatureFormat()

Determines the signature padding mode

public withSignatureFormat(string $format) : mixed

Valid values are: ASN1, SSH2, Raw

Parameters
$format : string
Tags
access

public

__construct()

Constructor

protected __construct() : mixed

PublicKey and PrivateKey objects can only be created from abstract RSA class

computek()

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

protected computek(string $h1) : string
Parameters
$h1 : string
Tags
access

public

Return values
string

initialize_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
access

protected

Return values
bool

validatePlugin()

Validate Plugin

protected static validatePlugin(string $format, string $type[, string $method = NULL ]) : mixed
Parameters
$format : string
$type : string
$method : string = NULL

optional

Tags
access

private

bits2octets()

Bit String to Octet String

private bits2octets(string $in) : string
Parameters
$in : string
Tags
access

private

Return values
string

loadPlugins()

Load Plugins

private static loadPlugins(string $format) : mixed
Parameters
$format : string
Tags
access

private


        
On this page

Search results