Package org.forgerock.json.jose.jwk
Class OkpJWK
java.lang.Object
org.forgerock.json.jose.jwk.JWK
org.forgerock.json.jose.jwk.OkpJWK
- All Implemented Interfaces:
EllipticCurveJwk
An Octet Key-Pair (OKP) JWK as defined in RFC 8037.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder object for Octet Key-Pair (OKP) JWKs. -
Field Summary
Fields inherited from class org.forgerock.json.jose.jwk.JWK
JSON_KEY_ALG, JSON_KEY_KID, JSON_KEY_KTY, JSON_KEY_OPERATIONS, JSON_KEY_USE, JSON_KEY_X5C, JSON_KEY_X5T, JSON_KEY_X5T_S256, JSON_KEY_X5U
-
Method Summary
Modifier and TypeMethodDescriptionstatic OkpJWK.Builder
builder()
Creates a new builder object for an OKP key.static OkpJWK
Generates a fresh OKP JWK with both public and private claims on the given curve.getD()
Returns the private key d value.The supported elliptic curve that this key is on.protected Optional<JWK.Builder<?>>
Return a builder with all the values set for representing the public components of the JWK.getX()
Returns the x-coordinate that forms the public key.boolean
Indicates if any private key attributes are present in the JWK.boolean
Determines whether the public key is valid.static OkpJWK
Parses a JWK from a JsonValue json object.Converts the public claims in the JWK into a public key object.Returns a json representation of the JWK.Converts the JWK to a key-pair.Converts the JWK to a private key object.Converts the public claims in the JWK into a public key.toString()
Returns a KeyPair object containing the XECPrivateKey and XECPublicKey for this JWK.Converts the JWK to a Java 11 XECPublicKey instance.Methods inherited from class org.forgerock.json.jose.jwk.JWK
getAlgorithm, getAlgorithm, getJwaAlgorithm, getJwkThumbprint, getKeyId, getKeyOperations, getKeyType, getUse, getX509Chain, getX509Thumbnail, getX509Thumbprint, getX509ThumbprintS256, getX509URL, loadJWKFromJson, parse, putField, toCryptoKey, toJsonString, toJsonValue, toPublicJwk, toSecretBuilder
-
Method Details
-
builder
Creates a new builder object for an OKP key.- Returns:
- the builder object.
-
getEllipticCurve
The supported elliptic curve that this key is on.- Specified by:
getEllipticCurve
in interfaceEllipticCurveJwk
- Returns:
- the curve.
-
getX
Returns the x-coordinate that forms the public key.- Returns:
- the public key x-coordinate.
-
getD
Returns the private key d value.- Returns:
- the private key d value.
-
parse
Parses a JWK from a JsonValue json object.- Parameters:
json
- JsonValue json object- Returns:
- a OctJWK object
-
toJsonValue
Description copied from class:JWK
Returns a json representation of the JWK.- Overrides:
toJsonValue
in classJWK
- Returns:
- A JSON representation.
-
toString
-
isPrivate
public boolean isPrivate()Description copied from class:JWK
Indicates if any private key attributes are present in the JWK. -
getPublicJwkBuilder
Description copied from class:JWK
Return a builder with all the values set for representing the public components of the JWK. Common JWK attributes will be added inJWK.toPublicJwk()
.- Specified by:
getPublicJwkBuilder
in classJWK
- Returns:
- The builder.
-
toPrivateKey
Converts the JWK to a private key object.- Returns:
- the equivalent private key object.
-
toXECPublicKey
Converts the JWK to a Java 11 XECPublicKey instance. If using Java prior to Java 11 then this returns null.- Returns:
- the XECPublicKey corresponding to this JWK.
-
toXECKeyPair
Returns a KeyPair object containing the XECPrivateKey and XECPublicKey for this JWK. Only supported in Java 11+. On earlier Java versions it will return a pair of null keys.- Returns:
- the XEC key pair.
-
toECPublicKey
Description copied from interface:EllipticCurveJwk
Converts the public claims in the JWK into a public key object. This method is only compatible with EcJWKs and will throw an exception if called on an OkpJWK.- Specified by:
toECPublicKey
in interfaceEllipticCurveJwk
- Returns:
- the public key.
-
toPublicKey
Description copied from interface:EllipticCurveJwk
Converts the public claims in the JWK into a public key. Note that the public key returned may not be an ECPublicKey. For instance, on Java 11 an OkpJWK may return a XECPrivateKey.- Specified by:
toPublicKey
in interfaceEllipticCurveJwk
- Returns:
- the public key.
-
isPublicKeyValid
public boolean isPublicKeyValid()Determines whether the public key is valid. Currently for Curve25519, we blacklist all the points of small-order given by https://cr.yp.to/ecdh.html#validate.- Specified by:
isPublicKeyValid
in interfaceEllipticCurveJwk
- Returns:
- true if the public key is a valid point on the curve.
-
toKeyPair
Converts the JWK to a key-pair.- Specified by:
toKeyPair
in interfaceEllipticCurveJwk
- Returns:
- the key-pair equivalent to this JWK.
-
generateKeyPair
Generates a fresh OKP JWK with both public and private claims on the given curve.- Parameters:
curve
- The curve to generate the key pair on.- Returns:
- the freshly generated JWK.
-