JWK
in package
JSON Web Key implementation, based on this spec: https://tools.ietf.org/html/draft-ietf-jose-json-web-key-41
PHP version 5
Tags
Table of Contents
Constants
- ASN1_BIT_STRING = 0x3
- ASN1_OBJECT_IDENTIFIER = 0x6
- ASN1_SEQUENCE = 0x10
- EC_CURVES = [ 'P-256' => '1.2.840.10045.3.1.7', // Len: 64 'secp256k1' => '1.3.132.0.10', // Len: 64 'P-384' => '1.3.132.0.34', ]
- OID = '1.2.840.10045.2.1'
- OKP_SUBTYPES = ['Ed25519' => true]
Methods
- parseKey() : Key
- Parse a JWK key
- parseKeySet() : array<string, Key>
- Parse a set of JWK keys
- createPemFromCrvAndXYCoordinates() : string
- Converts the EC JWK values to pem format.
- createPemFromModulusAndExponent() : string
- Create a public key represented in PEM format from RSA modulus and exponent information
- encodeDER() : string
- Encodes a value into a DER object.
- encodeLength() : string
- DER-encode the length
- encodeOID() : string
- Encodes a string into a DER-encoded OID.
Constants
ASN1_BIT_STRING
private
mixed
ASN1_BIT_STRING
= 0x3
ASN1_OBJECT_IDENTIFIER
private
mixed
ASN1_OBJECT_IDENTIFIER
= 0x6
ASN1_SEQUENCE
private
mixed
ASN1_SEQUENCE
= 0x10
EC_CURVES
private
mixed
EC_CURVES
= [
'P-256' => '1.2.840.10045.3.1.7',
// Len: 64
'secp256k1' => '1.3.132.0.10',
// Len: 64
'P-384' => '1.3.132.0.34',
]
OID
private
mixed
OID
= '1.2.840.10045.2.1'
OKP_SUBTYPES
private
mixed
OKP_SUBTYPES
= ['Ed25519' => true]
Methods
parseKey()
Parse a JWK key
public
static parseKey(array<string|int, mixed> $jwk[, string $defaultAlg = null ]) : Key
Parameters
- $jwk : array<string|int, mixed>
-
An individual JWK
- $defaultAlg : string = null
-
The algorithm for the Key object if "alg" is not set in the JSON Web Key Set
Tags
Return values
Key —The key object for the JWK
parseKeySet()
Parse a set of JWK keys
public
static parseKeySet(array<string|int, mixed> $jwks[, string $defaultAlg = null ]) : array<string, Key>
Parameters
- $jwks : array<string|int, mixed>
-
The JSON Web Key Set as an associative array
- $defaultAlg : string = null
-
The algorithm for the Key object if "alg" is not set in the JSON Web Key Set
Tags
Return values
array<string, Key> —An associative array of key IDs (kid) to Key objects
createPemFromCrvAndXYCoordinates()
Converts the EC JWK values to pem format.
private
static createPemFromCrvAndXYCoordinates(string $crv, string $x, string $y) : string
Parameters
- $crv : string
-
The EC curve (only P-256 & P-384 is supported)
- $x : string
-
The EC x-coordinate
- $y : string
-
The EC y-coordinate
Return values
stringcreatePemFromModulusAndExponent()
Create a public key represented in PEM format from RSA modulus and exponent information
private
static createPemFromModulusAndExponent(string $n, string $e) : string
Parameters
- $n : string
-
The RSA modulus encoded in Base64
- $e : string
-
The RSA exponent encoded in Base64
Tags
Return values
string —The RSA public key represented in PEM format
encodeDER()
Encodes a value into a DER object.
private
static encodeDER(int $type, string $value) : string
Also defined in Firebase\JWT\JWT
Parameters
- $type : int
-
DER tag
- $value : string
-
the value to encode
Return values
string —the encoded object
encodeLength()
DER-encode the length
private
static encodeLength(int $length) : string
DER supports lengths up to (2**8)127, however, we'll only support lengths up to (28)**4. See X.690 paragraph 8.1.3 for more information.
Parameters
- $length : int
Return values
stringencodeOID()
Encodes a string into a DER-encoded OID.
private
static encodeOID(string $oid) : string
Parameters
- $oid : string
-
the OID string
Return values
string —the binary DER-encoded OID