Documentation

PKCS8 extends PKCS8
in package
uses Common

AbstractYes

PKCS#8 Formatted EC Key Handler

Tags
author

Jim Wigginton terrafrost@php.net

access

public

Table of Contents

Constants

MODE_ANY  = 0
Auto-detect the format
MODE_DER  = 2
Require raw DER's be supplied
MODE_PEM  = 1
Require base64-encoded PEM's be supplied
OID_NAME  = ['id-ecPublicKey', 'id-Ed25519', 'id-Ed448']
OID Name
OID_VALUE  = ['1.2.840.10045.2.1', '1.3.101.112', '1.3.101.113']
OID Value

Properties

$childOIDsLoaded  : bool
Child OIDs loaded
$format  : int
Is the key a base-64 encoded PEM, DER or should it be auto-detected?
$curveOIDs  : array<string|int, mixed>
Curve OIDs
$defaultEncryptionAlgorithm  : string
Default encryption algorithm
$defaultEncryptionScheme  : string
Default encryption scheme
$defaultIterationCount  : int
Default Iteration Count
$defaultPRF  : string
Default PRF
$oidsLoaded  : bool
OIDs loaded
$useNamedCurves  : bool
Use Named Curves

Methods

extractEncryptionAlgorithm()  : array<string|int, mixed>
Returns the encryption parameters used by the key
extractPoint()  : array<string|int, object>
Extract points from a string
load()  : array<string|int, mixed>
Break a public or private key down into its constituent components
requireAny()  : mixed
Accept any format and auto detect the format
requireDER()  : mixed
Require raw DER's be supplied
requirePEM()  : mixed
Require base64-encoded PEM's be supplied
savePrivateKey()  : string
Convert a private key to the appropriate format.
savePublicKey()  : string
Convert an EC public key to the appropriate format
setEncryptionAlgorithm()  : mixed
Sets the default encryption algorithm
setEncryptionScheme()  : mixed
Sets the default encryption algorithm for PBES2
setImplicitCurve()  : mixed
Explicitly set the curve
setIterationCount()  : mixed
Sets the iteration count
setPRF()  : mixed
Sets the PRF for PBES2
useNamedCurve()  : mixed
Use Named Curve
useSpecifiedCurve()  : mixed
Use Specified Curve
loadCurveByParam()  : Base|false
Returns an instance of \phpseclib3\Crypt\EC\BaseCurves\Base based on the curve parameters
wrapPrivateKey()  : string
Wrap a private key appropriately
wrapPublicKey()  : string
Wrap a public key appropriately
encodeParameters()  : string|false
Encode Parameters
getPBES1EncryptionObject()  : SymmetricKey
Returns a SymmetricKey object based on a PBES1 $algo
getPBES1Hash()  : string
Returns a hash based on a PBES1 $algo
getPBES1KDF()  : string
Returns a KDF baesd on a PBES1 $algo
getPBES2EncryptionObject()  : SymmetricKey
Returns a SymmetricKey object baesd on a PBES2 $algo
initialize_static_variables()  : mixed
Initialize static variables
loadEdDSA()  : array<string|int, mixed>
Break a public or private EdDSA key down into its constituent components
preParse()  : array<string|int, mixed>
Perform some preliminary parsing of the key

Constants

MODE_ANY

Auto-detect the format

public mixed MODE_ANY = 0

MODE_DER

Require raw DER's be supplied

public mixed MODE_DER = 2

MODE_PEM

Require base64-encoded PEM's be supplied

public mixed MODE_PEM = 1

OID_NAME

OID Name

public array<string|int, mixed> OID_NAME = ['id-ecPublicKey', 'id-Ed25519', 'id-Ed448']
Tags
access

private

OID_VALUE

OID Value

public string OID_VALUE = ['1.2.840.10045.2.1', '1.3.101.112', '1.3.101.113']
Tags
access

private

Properties

$childOIDsLoaded

Child OIDs loaded

protected static bool $childOIDsLoaded = false

$format

Is the key a base-64 encoded PEM, DER or should it be auto-detected?

protected static int $format = self::MODE_ANY
Tags
access

private

$curveOIDs

Curve OIDs

private static array<string|int, mixed> $curveOIDs = []

$defaultEncryptionAlgorithm

Default encryption algorithm

private static string $defaultEncryptionAlgorithm = 'id-PBES2'
Tags
access

private

$defaultEncryptionScheme

Default encryption scheme

private static string $defaultEncryptionScheme = 'aes128-CBC-PAD'

Only used when defaultEncryptionAlgorithm is id-PBES2

Tags
access

private

$defaultIterationCount

Default Iteration Count

private static int $defaultIterationCount = 2048
Tags
access

private

$defaultPRF

Default PRF

private static string $defaultPRF = 'id-hmacWithSHA256'

Only used when defaultEncryptionAlgorithm is id-PBES2

Tags
access

private

$oidsLoaded

OIDs loaded

private static bool $oidsLoaded = false
Tags
access

private

$useNamedCurves

Use Named Curves

private static bool $useNamedCurves = true

Methods

extractEncryptionAlgorithm()

Returns the encryption parameters used by the key

public static extractEncryptionAlgorithm(string $key) : array<string|int, mixed>
Parameters
$key : string
Return values
array<string|int, mixed>

extractPoint()

Extract points from a string

public static extractPoint(string $str, Base $curve) : array<string|int, object>

Supports both compressed and uncompressed points

Parameters
$str : string
$curve : Base
Return values
array<string|int, object>

load()

Break a public or private key down into its constituent components

public static load(string $key[, string $password = '' ]) : array<string|int, mixed>
Parameters
$key : string
$password : string = ''

optional

Tags
access

public

Return values
array<string|int, mixed>

requireAny()

Accept any format and auto detect the format

public static requireAny() : mixed

This is the default setting

Tags
access

public

requireDER()

Require raw DER's be supplied

public static requireDER() : mixed
Tags
access

public

requirePEM()

Require base64-encoded PEM's be supplied

public static requirePEM() : mixed
Tags
access

public

savePrivateKey()

Convert a private key to the appropriate format.

public static savePrivateKey(Integer $privateKey, Base $curve, array<string|int, Integer$publicKey[, string $password = '' ][, array<string|int, mixed> $options = [] ]) : string
Parameters
$privateKey : Integer
$curve : Base
$publicKey : array<string|int, Integer>
$password : string = ''

optional

$options : array<string|int, mixed> = []

optional

Tags
access

public

Return values
string

savePublicKey()

Convert an EC public key to the appropriate format

public static savePublicKey(Base $curve, array<string|int, Integer$publicKey[, array<string|int, mixed> $options = [] ]) : string
Parameters
$curve : Base
$publicKey : array<string|int, Integer>
$options : array<string|int, mixed> = []

optional

Tags
access

public

Return values
string

setEncryptionAlgorithm()

Sets the default encryption algorithm

public static setEncryptionAlgorithm(string $algo) : mixed
Parameters
$algo : string
Tags
access

public

setEncryptionScheme()

Sets the default encryption algorithm for PBES2

public static setEncryptionScheme(string $algo) : mixed
Parameters
$algo : string
Tags
access

public

setImplicitCurve()

Explicitly set the curve

public static setImplicitCurve(Base $curve) : mixed

If the key contains an implicit curve phpseclib needs the curve to be explicitly provided

Parameters
$curve : Base

setIterationCount()

Sets the iteration count

public static setIterationCount(int $count) : mixed
Parameters
$count : int
Tags
access

public

setPRF()

Sets the PRF for PBES2

public static setPRF(string $algo) : mixed
Parameters
$algo : string
Tags
access

public

useNamedCurve()

Use Named Curve

public static useNamedCurve() : mixed

A named curve does not include any parameters. It is up to the EC parameters to know what the coefficients, the base points, etc, are from the name of the curve. A named curve is a more concise way of representing a curve

useSpecifiedCurve()

Use Specified Curve

public static useSpecifiedCurve() : mixed

A specified curve has all the coefficients, the base points, etc, explicitely included. A specified curve is a more verbose way of representing a curve

loadCurveByParam()

Returns an instance of \phpseclib3\Crypt\EC\BaseCurves\Base based on the curve parameters

protected static loadCurveByParam(array<string|int, mixed> $params) : Base|false
Parameters
$params : array<string|int, mixed>
Return values
Base|false

wrapPrivateKey()

Wrap a private key appropriately

protected static wrapPrivateKey(string $key, string $attr, mixed $params, string $password[, string $oid = null ][, string $publicKey = '' ][, array<string|int, mixed> $options = [] ]) : string
Parameters
$key : string
$attr : string
$params : mixed
$password : string
$oid : string = null

optional

$publicKey : string = ''

optional

$options : array<string|int, mixed> = []

optional

Tags
access

public

Return values
string

wrapPublicKey()

Wrap a public key appropriately

protected static wrapPublicKey(string $key, mixed $params[, string $oid = null ]) : string
Parameters
$key : string
$params : mixed
$oid : string = null
Tags
access

public

Return values
string

encodeParameters()

Encode Parameters

private static encodeParameters(Base $curve[, bool $returnArray = false ][, array<string|int, mixed> $options = [] ]) : string|false
Parameters
$curve : Base
$returnArray : bool = false

optional

$options : array<string|int, mixed> = []

optional

Tags
todo

Maybe at some point this could be moved to __toString() for each of the curves?

Return values
string|false

getPBES1EncryptionObject()

Returns a SymmetricKey object based on a PBES1 $algo

private static getPBES1EncryptionObject(string $algo) : SymmetricKey
Parameters
$algo : string
Tags
access

public

Return values
SymmetricKey

getPBES1Hash()

Returns a hash based on a PBES1 $algo

private static getPBES1Hash(string $algo) : string
Parameters
$algo : string
Tags
access

public

Return values
string

getPBES1KDF()

Returns a KDF baesd on a PBES1 $algo

private static getPBES1KDF(string $algo) : string
Parameters
$algo : string
Tags
access

public

Return values
string

getPBES2EncryptionObject()

Returns a SymmetricKey object baesd on a PBES2 $algo

private static getPBES2EncryptionObject(string $algo) : SymmetricKey
Parameters
$algo : string
Tags
access

public

Return values
SymmetricKey

initialize_static_variables()

Initialize static variables

private static initialize_static_variables() : mixed

loadEdDSA()

Break a public or private EdDSA key down into its constituent components

private static loadEdDSA(array<string|int, mixed> $key) : array<string|int, mixed>
Parameters
$key : array<string|int, mixed>
Return values
array<string|int, mixed>

preParse()

Perform some preliminary parsing of the key

private static preParse(string &$key) : array<string|int, mixed>
Parameters
$key : string
Return values
array<string|int, mixed>

        
On this page

Search results