Package com.nimbusds.jose.jwk
Class OctetKeyPair
- java.lang.Object
-
- com.nimbusds.jose.jwk.JWK
-
- com.nimbusds.jose.jwk.OctetKeyPair
-
- All Implemented Interfaces:
AsymmetricJWK,CurveBasedJWK,Serializable
@Immutable public class OctetKeyPair extends JWK implements AsymmetricJWK, CurveBasedJWK
Octet key pairJSON Web Key (JWK), used to represent Edwards-curve keys. This class is immutable.Supported curves:
Example JSON object representation of a public OKP JWK:
{ "kty" : "OKP", "crv" : "Ed25519", "x" : "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo", "use" : "sig", "kid" : "1" }Example JSON object representation of a private OKP JWK:
{ "kty" : "OKP", "crv" : "Ed25519", "x" : "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo", "d" : "nWGxne_9WmC6hEr0kuwsxERJxWl7MmkZcDusAxyuf2A", "use" : "sig", "kid" : "1" }Use the builder to create a new OKP JWK:
OctetKeyPair key = new OctetKeyPair.Builder(Curve.Ed25519, x) .keyUse(KeyUse.SIGNATURE) .keyID("1") .build();- Version:
- 2022-12-26
- Author:
- Vladimir Dzhuvinov
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOctetKeyPair.BuilderBuilder for constructing Octet Key Pair JWKs.
-
Field Summary
Fields Modifier and Type Field Description static Set<Curve>SUPPORTED_CURVESSupported Edwards curves.
-
Constructor Summary
Constructors Constructor Description OctetKeyPair(Curve crv, Base64URL x, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks)Deprecated.OctetKeyPair(Curve crv, Base64URL x, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, Date exp, Date nbf, Date iat, KeyStore ks)Creates a new public Octet Key Pair JSON Web Key (JWK) with the specified parameters.OctetKeyPair(Curve crv, Base64URL x, Base64URL d, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks)Deprecated.OctetKeyPair(Curve crv, Base64URL x, Base64URL d, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, Date exp, Date nbf, Date iat, KeyStore ks)Creates a new public / private Octet Key Pair JSON Web Key (JWK) with the specified parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)CurvegetCurve()Returns the cryptographic curve.Base64URLgetD()Gets the private 'd' parameter.byte[]getDecodedD()Gets the private 'd' parameter, decoded from Base64.byte[]getDecodedX()Gets the public 'x' parameter, decoded from Base64.LinkedHashMap<String,?>getRequiredParams()Returns the required JWK parameters.Base64URLgetX()Gets the public 'x' parameter.inthashCode()booleanisPrivate()Returnstrueif this JWK contains private or sensitive (non-public) parameters.booleanmatches(X509Certificate cert)Returnstrueif the public key material of this JWK matches the public subject key info of the specified X.509 certificate.static OctetKeyPairparse(String s)Parses a public / private Octet Key Pair JWK from the specified JSON object string representation.static OctetKeyPairparse(Map<String,Object> jsonObject)Parses a public / private Octet Key Pair JWK from the specified JSON object representation.intsize()Returns the size of this JWK.Map<String,Object>toJSONObject()Returns a JSON object representation of this JWK.KeyPairtoKeyPair()Returns a Java key pair representation of this JWK.PrivateKeytoPrivateKey()Returns a Java private key representation of this JWK.OctetKeyPairtoPublicJWK()Returns a copy of this Octet Key Pair JWK with any private values removed.PublicKeytoPublicKey()Returns a Java public key representation of the JWK.-
Methods inherited from class com.nimbusds.jose.jwk.JWK
computeThumbprint, computeThumbprint, computeThumbprintURI, getAlgorithm, getExpirationTime, getIssueTime, getKeyID, getKeyOperations, getKeyStore, getKeyType, getKeyUse, getNotBeforeTime, getParsedX509CertChain, getX509CertChain, getX509CertSHA256Thumbprint, getX509CertThumbprint, getX509CertURL, load, parse, parseFromPEMEncodedObjects, parseFromPEMEncodedX509Cert, toECKey, toJSONString, toOctetKeyPair, toOctetSequenceKey, toRSAKey, toString
-
-
-
-
Field Detail
-
SUPPORTED_CURVES
public static final Set<Curve> SUPPORTED_CURVES
Supported Edwards curves.
-
-
Constructor Detail
-
OctetKeyPair
@Deprecated public OctetKeyPair(Curve crv, Base64URL x, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks)
Deprecated.Creates a new public Octet Key Pair JSON Web Key (JWK) with the specified parameters.- Parameters:
crv- The cryptographic curve. Must not benull.x- The public 'x' parameter. Must not benull.use- The key use,nullif not specified or if the key is intended for signing as well as encryption.ops- The key operations,nullif not specified.alg- The intended JOSE algorithm for the key,nullif not specified.kid- The key ID,nullif not specified.x5u- The X.509 certificate URL,nullif not specified.x5t- The X.509 certificate SHA-1 thumbprint,nullif not specified.x5t256- The X.509 certificate SHA-256 thumbprint,nullif not specified.x5c- The X.509 certificate chain,nullif not specified.ks- Reference to the underlying key store,nullif not specified.
-
OctetKeyPair
@Deprecated public OctetKeyPair(Curve crv, Base64URL x, Base64URL d, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks)
Deprecated.Creates a new public / private Octet Key Pair JSON Web Key (JWK) with the specified parameters.- Parameters:
crv- The cryptographic curve. Must not benull.x- The public 'x' parameter. Must not benull.d- The private 'd' parameter. Must not benull.use- The key use,nullif not specified or if the key is intended for signing as well as encryption.ops- The key operations,nullif not specified.alg- The intended JOSE algorithm for the key,nullif not specified.kid- The key ID,nullif not specified.x5u- The X.509 certificate URL,nullif not specified.x5t- The X.509 certificate SHA-1 thumbprint,nullif not specified.x5t256- The X.509 certificate SHA-256 thumbprint,nullif not specified.x5c- The X.509 certificate chain,nullif not specified.ks- Reference to the underlying key store,nullif not specified.
-
OctetKeyPair
public OctetKeyPair(Curve crv, Base64URL x, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, Date exp, Date nbf, Date iat, KeyStore ks)
Creates a new public Octet Key Pair JSON Web Key (JWK) with the specified parameters.- Parameters:
crv- The cryptographic curve. Must not benull.x- The public 'x' parameter. Must not benull.use- The key use,nullif not specified or if the key is intended for signing as well as encryption.ops- The key operations,nullif not specified.alg- The intended JOSE algorithm for the key,nullif not specified.kid- The key ID,nullif not specified.x5u- The X.509 certificate URL,nullif not specified.x5t- The X.509 certificate SHA-1 thumbprint,nullif not specified.x5t256- The X.509 certificate SHA-256 thumbprint,nullif not specified.x5c- The X.509 certificate chain,nullif not specified.exp- The key expiration time,nullif not specified.nbf- The key not-before time,nullif not specified.iat- The key issued-at time,nullif not specified.ks- Reference to the underlying key store,nullif not specified.
-
OctetKeyPair
public OctetKeyPair(Curve crv, Base64URL x, Base64URL d, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, Date exp, Date nbf, Date iat, KeyStore ks)
Creates a new public / private Octet Key Pair JSON Web Key (JWK) with the specified parameters.- Parameters:
crv- The cryptographic curve. Must not benull.x- The public 'x' parameter. Must not benull.d- The private 'd' parameter. Must not benull.use- The key use,nullif not specified or if the key is intended for signing as well as encryption.ops- The key operations,nullif not specified.alg- The intended JOSE algorithm for the key,nullif not specified.kid- The key ID,nullif not specified.x5u- The X.509 certificate URL,nullif not specified.x5t- The X.509 certificate SHA-1 thumbprint,nullif not specified.x5t256- The X.509 certificate SHA-256 thumbprint,nullif not specified.x5c- The X.509 certificate chain,nullif not specified.exp- The key expiration time,nullif not specified.nbf- The key not-before time,nullif not specified.iat- The key issued-at time,nullif not specified.ks- Reference to the underlying key store,nullif not specified.
-
-
Method Detail
-
getCurve
public Curve getCurve()
Description copied from interface:CurveBasedJWKReturns the cryptographic curve.- Specified by:
getCurvein interfaceCurveBasedJWK- Returns:
- The cryptographic curve.
-
getDecodedX
public byte[] getDecodedX()
Gets the public 'x' parameter, decoded from Base64.- Returns:
- The public 'x' parameter in bytes.
-
getD
public Base64URL getD()
Gets the private 'd' parameter.- Returns:
- The private 'd' coordinate,
nullif not specified (for a public key).
-
getDecodedD
public byte[] getDecodedD()
Gets the private 'd' parameter, decoded from Base64.- Returns:
- The private 'd' coordinate in bytes,
nullif not specified (for a public key).
-
toPublicKey
public PublicKey toPublicKey() throws JOSEException
Description copied from interface:AsymmetricJWKReturns a Java public key representation of the JWK.- Specified by:
toPublicKeyin interfaceAsymmetricJWK- Returns:
- The Java public key.
- Throws:
JOSEException- If conversion failed or is not supported.
-
toPrivateKey
public PrivateKey toPrivateKey() throws JOSEException
Description copied from interface:AsymmetricJWKReturns a Java private key representation of this JWK.- Specified by:
toPrivateKeyin interfaceAsymmetricJWK- Returns:
- The Java private key,
nullif not specified. - Throws:
JOSEException- If conversion failed or is not supported.
-
toKeyPair
public KeyPair toKeyPair() throws JOSEException
Description copied from interface:AsymmetricJWKReturns a Java key pair representation of this JWK.- Specified by:
toKeyPairin interfaceAsymmetricJWK- Returns:
- The Java key pair. The private key will be
nullif not specified. - Throws:
JOSEException- If conversion failed or is not supported.
-
matches
public boolean matches(X509Certificate cert)
Description copied from interface:AsymmetricJWKReturnstrueif the public key material of this JWK matches the public subject key info of the specified X.509 certificate.- Specified by:
matchesin interfaceAsymmetricJWK- Parameters:
cert- The X.509 certificate. Must not benull.- Returns:
trueif the public key material of this JWK matches the public subject key info of the specified X.509 certificate, elsefalse.
-
getRequiredParams
public LinkedHashMap<String,?> getRequiredParams()
Description copied from class:JWKReturns the required JWK parameters. Intended as input for JWK thumbprint computation. See RFC 7638 for more information.- Specified by:
getRequiredParamsin classJWK- Returns:
- The required JWK parameters, sorted alphanumerically by key name and ready for JSON serialisation.
-
isPrivate
public boolean isPrivate()
Description copied from class:JWKReturnstrueif this JWK contains private or sensitive (non-public) parameters.
-
toPublicJWK
public OctetKeyPair toPublicJWK()
Returns a copy of this Octet Key Pair JWK with any private values removed.- Specified by:
toPublicJWKin classJWK- Returns:
- The copied public Octet Key Pair JWK.
-
toJSONObject
public Map<String,Object> toJSONObject()
Description copied from class:JWKReturns a JSON object representation of this JWK. This method is intended to be called from extending classes.Example:
{ "kty" : "RSA", "use" : "sig", "kid" : "fd28e025-8d24-48bc-a51a-e2ffc8bc274b" }- Overrides:
toJSONObjectin classJWK- Returns:
- The JSON object representation.
-
parse
public static OctetKeyPair parse(String s) throws ParseException
Parses a public / private Octet Key Pair JWK from the specified JSON object string representation.- Parameters:
s- The JSON object string to parse. Must not benull.- Returns:
- The public / private Octet Key Pair JWK.
- Throws:
ParseException- If the string couldn't be parsed to an Octet Key Pair JWK.
-
parse
public static OctetKeyPair parse(Map<String,Object> jsonObject) throws ParseException
Parses a public / private Octet Key Pair JWK from the specified JSON object representation.- Parameters:
jsonObject- The JSON object to parse. Must not benull.- Returns:
- The public / private Octet Key Pair JWK.
- Throws:
ParseException- If the JSON object couldn't be parsed to an Octet Key Pair JWK.
-
-