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
public class OkpJWK extends JWK implements EllipticCurveJwk
An Octet Key-Pair (OKP) JWK as defined in RFC 8037.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OkpJWK.Builder
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static OkpJWK.Builder
builder()
Creates a new builder object for an OKP key.static OkpJWK
generateKeyPair(SupportedEllipticCurve curve)
Generates a fresh OKP JWK with both public and private claims on the given curve.String
getD()
Returns the private key d value.SupportedEllipticCurve
getEllipticCurve()
The supported elliptic curve that this key is on.protected Optional<JWK.Builder<?>>
getPublicJwkBuilder()
Return a builder with all the values set for representing the public components of the JWK.String
getX()
Returns the x-coordinate that forms the public key.boolean
isPrivate()
Indicates if any private key attributes are present in the JWK.boolean
isPublicKeyValid()
Determines whether the public key is valid.static OkpJWK
parse(JsonValue json)
Parses a JWK from a JsonValue json object.ECPublicKey
toECPublicKey()
Converts the public claims in the JWK into a public key object.JsonValue
toJsonValue()
Returns a json representation of the JWK.KeyPair
toKeyPair()
Converts the JWK to a key-pair.PrivateKey
toPrivateKey()
Converts the JWK to a private key object.PublicKey
toPublicKey()
Converts the public claims in the JWK into a public key.String
toString()
KeyPair
toXECKeyPair()
Returns a KeyPair object containing the XECPrivateKey and XECPublicKey for this JWK.PublicKey
toXECPublicKey()
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
-
-
-
-
Method Detail
-
builder
public static OkpJWK.Builder builder()
Creates a new builder object for an OKP key.- Returns:
- the builder object.
-
getEllipticCurve
public SupportedEllipticCurve getEllipticCurve()
The supported elliptic curve that this key is on.- Specified by:
getEllipticCurve
in interfaceEllipticCurveJwk
- Returns:
- the curve.
-
getX
public String getX()
Returns the x-coordinate that forms the public key.- Returns:
- the public key x-coordinate.
-
getD
public String getD()
Returns the private key d value.- Returns:
- the private key d value.
-
parse
public static OkpJWK parse(JsonValue json)
Parses a JWK from a JsonValue json object.- Parameters:
json
- JsonValue json object- Returns:
- a OctJWK object
-
toJsonValue
public JsonValue toJsonValue()
Description copied from class:JWK
Returns a json representation of the JWK.- Overrides:
toJsonValue
in classJWK
- Returns:
- A JSON representation.
-
isPrivate
public boolean isPrivate()
Description copied from class:JWK
Indicates if any private key attributes are present in the JWK.
-
getPublicJwkBuilder
protected Optional<JWK.Builder<?>> 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
public PrivateKey toPrivateKey()
Converts the JWK to a private key object.- Returns:
- the equivalent private key object.
-
toXECPublicKey
public PublicKey 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
public KeyPair 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
public ECPublicKey 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
public PublicKey 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
public KeyPair toKeyPair()
Converts the JWK to a key-pair.- Specified by:
toKeyPair
in interfaceEllipticCurveJwk
- Returns:
- the key-pair equivalent to this JWK.
-
generateKeyPair
public static OkpJWK generateKeyPair(SupportedEllipticCurve curve)
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.
-
-