Class RSAKey
- All Implemented Interfaces:
AsymmetricJWK,Serializable
RSA JSON Web Key (JWK). This class is
immutable.
Provides RSA JWK import from / export to the following standard Java interfaces and classes:
RSAPublicKeyRSAPrivateKeyPrivateKeyfor an RSA key in a PKCS#11 storeKeyPair
Example JSON object representation of a public RSA JWK:
{
"kty" : "RSA",
"n" : "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx
4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMs
tn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2
QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbI
SD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqb
w0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw",
"e" : "AQAB",
"alg" : "RS256",
"kid" : "2011-04-29"
}
Example JSON object representation of a public and private RSA JWK (with both the first and the second private key representations):
{
"kty" : "RSA",
"n" : "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx
4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMs
tn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2
QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbI
SD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqb
w0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw",
"e" : "AQAB",
"d" : "X4cTteJY_gn4FYPsXB8rdXix5vwsg1FLN5E3EaG6RJoVH-HLLKD9
M7dx5oo7GURknchnrRweUkC7hT5fJLM0WbFAKNLWY2vv7B6NqXSzUvxT0_YSfqij
wp3RTzlBaCxWp4doFk5N2o8Gy_nHNKroADIkJ46pRUohsXywbReAdYaMwFs9tv8d
_cPVY3i07a3t8MN6TNwm0dSawm9v47UiCl3Sk5ZiG7xojPLu4sbg1U2jx4IBTNBz
nbJSzFHK66jT8bgkuqsk0GjskDJk19Z4qwjwbsnn4j2WBii3RL-Us2lGVkY8fkFz
me1z0HbIkfz0Y6mqnOYtqc0X4jfcKoAC8Q",
"p" : "83i-7IvMGXoMXCskv73TKr8637FiO7Z27zv8oj6pbWUQyLPQBQxtPV
nwD20R-60eTDmD2ujnMt5PoqMrm8RfmNhVWDtjjMmCMjOpSXicFHj7XOuVIYQyqV
WlWEh6dN36GVZYk93N8Bc9vY41xy8B9RzzOGVQzXvNEvn7O0nVbfs",
"q" : "3dfOR9cuYq-0S-mkFLzgItgMEfFzB2q3hWehMuG0oCuqnb3vobLyum
qjVZQO1dIrdwgTnCdpYzBcOfW5r370AFXjiWft_NGEiovonizhKpo9VVS78TzFgx
kIdrecRezsZ-1kYd_s1qDbxtkDEgfAITAG9LUnADun4vIcb6yelxk",
"dp" : "G4sPXkc6Ya9y8oJW9_ILj4xuppu0lzi_H7VTkS8xj5SdX3coE0oim
YwxIi2emTAue0UOa5dpgFGyBJ4c8tQ2VF402XRugKDTP8akYhFo5tAA77Qe_Nmtu
YZc3C3m3I24G2GvR5sSDxUyAN2zq8Lfn9EUms6rY3Ob8YeiKkTiBj0",
"dq" : "s9lAH9fggBsoFR8Oac2R_E2gw282rT2kGOAhvIllETE1efrA6huUU
vMfBcMpn8lqeW6vzznYY5SSQF7pMdC_agI3nG8Ibp1BUb0JUiraRNqUfLhcQb_d9
GF4Dh7e74WbRsobRonujTYN1xCaP6TO61jvWrX-L18txXw494Q_cgk",
"qi" : "GyM_p6JrXySiz1toFgKbWV-JdI3jQ4ypu9rbMWx3rQJBfmt0FoYzg
UIZEVFEcOqwemRN81zoDAaa-Bk0KWNGDjJHZDdDmFhW3AN7lI-puxk_mHZGJ11rx
yR8O55XLSe3SPmRfKwZI6yU24ZxvQKFYItdldUKGzO6Ia6zTKhAVRU",
"alg" : "RS256",
"kid" : "2011-04-29"
}
Use the builder to create a new RSA JWK:
RSAKey key = new RSAKey.Builder(n, e)
.keyUse(KeyUse.SIGNATURE)
.keyID("123")
.build();
See RFC 3447.
See http://en.wikipedia.org/wiki/RSA_%28algorithm%29
- Version:
- 2022-12-26
- Author:
- Vladimir Dzhuvinov, Justin Richer, Cedric Staub
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for constructing RSA JWKs.static classOther Primes Info, represents the privateothparameter of a RSA JWK. -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionRSAKey(Base64URL n, Base64URL e, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks) Deprecated.RSAKey(Base64URL n, Base64URL e, 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 RSA JSON Web Key (JWK) with the specified parameters.RSAKey(Base64URL n, Base64URL e, Base64URL d, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks) Deprecated.RSAKey(Base64URL n, Base64URL e, 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 RSA JSON Web Key (JWK) with the specified parameters.RSAKey(Base64URL n, Base64URL e, Base64URL d, Base64URL p, Base64URL q, Base64URL dp, Base64URL dq, Base64URL qi, List<RSAKey.OtherPrimesInfo> oth, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c) Deprecated.RSAKey(Base64URL n, Base64URL e, Base64URL d, Base64URL p, Base64URL q, Base64URL dp, Base64URL dq, Base64URL qi, List<RSAKey.OtherPrimesInfo> oth, PrivateKey prv, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks) Deprecated.RSAKey(Base64URL n, Base64URL e, Base64URL d, Base64URL p, Base64URL q, Base64URL dp, Base64URL dq, Base64URL qi, List<RSAKey.OtherPrimesInfo> oth, PrivateKey prv, 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 RSA JSON Web Key (JWK) with the specified parameters.RSAKey(Base64URL n, Base64URL e, Base64URL p, Base64URL q, Base64URL dp, Base64URL dq, Base64URL qi, List<RSAKey.OtherPrimesInfo> oth, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks) Deprecated.RSAKey(Base64URL n, Base64URL e, Base64URL p, Base64URL q, Base64URL dp, Base64URL dq, Base64URL qi, List<RSAKey.OtherPrimesInfo> oth, 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 RSA JSON Web Key (JWK) with the specified parameters.RSAKey(RSAPublicKey pub, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks) Deprecated.RSAKey(RSAPublicKey pub, 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 RSA JSON Web Key (JWK) with the specified parameters.RSAKey(RSAPublicKey pub, RSAMultiPrimePrivateCrtKey priv, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks) Deprecated.RSAKey(RSAPublicKey pub, RSAMultiPrimePrivateCrtKey priv, 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 RSA JSON Web Key (JWK) with the specified parameters.RSAKey(RSAPublicKey pub, RSAPrivateCrtKey priv, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks) Deprecated.RSAKey(RSAPublicKey pub, RSAPrivateCrtKey priv, 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 RSA JSON Web Key (JWK) with the specified parameters.RSAKey(RSAPublicKey pub, RSAPrivateKey priv, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks) Deprecated.RSAKey(RSAPublicKey pub, RSAPrivateKey priv, 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 RSA JSON Web Key (JWK) with the specified parameters.RSAKey(RSAPublicKey pub, PrivateKey priv, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c, KeyStore ks) Deprecated.RSAKey(RSAPublicKey pub, PrivateKey priv, 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 RSA JSON Web Key (JWK) with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets the first Chinese Remainder Theorem (CRT) coefficient (qi)} of the private RSA key.Gets the first factor Chinese Remainder Theorem (CRT) exponent (dp) of the private RSA key.Gets the first prime factor (p) of the private RSA key.Gets the modulus value (n) of the RSA key.Gets the other primes information (oth) for the private RSA key, should they exist.Gets the private exponent (d) of the RSA key.Gets the public exponent (e) of the RSA key.Returns the required JWK parameters.Gets the second factor Chinese Remainder Theorem (CRT) exponent (dq) of the private RSA key.Gets the second prime factor (q) of the private RSA key.inthashCode()booleanReturnstrueif this JWK contains private or sensitive (non-public) parameters.static RSAKeyLoads a public / private RSA JWK from the specified JCA key store.booleanmatches(X509Certificate cert) Returnstrueif the public key material of this JWK matches the public subject key info of the specified X.509 certificate.static RSAKeyParses a public / private RSA JWK from the specified JSON object string representation.static RSAKeyparse(X509Certificate cert) Parses a public RSA JWK from the specified X.509 certificate.static RSAKeyParses a public / private RSA JWK from the specified JSON object representation.intsize()Returns the size of this JWK.Returns a JSON object representation of this JWK.Returns a standardjava.security.KeyPairrepresentation of this RSA JWK.Returns a Java private key representation of this JWK.Returns a copy of this RSA JWK with any private values removed.Returns a Java public key representation of the JWK.Returns a standardjava.security.interfaces.RSAPrivateKeyrepresentation of this RSA JWK.Returns a standardjava.security.interfaces.RSAPublicKeyrepresentation of this RSA 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, parseFromPEMEncodedObjects, parseFromPEMEncodedX509Cert, toECKey, toJSONString, toOctetKeyPair, toOctetSequenceKey, toRSAKey, toString
-
Constructor Details
-
RSAKey
@Deprecated public RSAKey(Base64URL n, Base64URL e, 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 RSA JSON Web Key (JWK) with the specified parameters.- Parameters:
n- The the modulus value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.e- The exponent value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. 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.
-
RSAKey
public RSAKey(Base64URL n, Base64URL e, 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 RSA JSON Web Key (JWK) with the specified parameters.- Parameters:
n- The the modulus value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.e- The exponent value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. 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.
-
RSAKey
@Deprecated public RSAKey(Base64URL n, Base64URL e, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by its first representation (see RFC 3447, section 3.2).- Parameters:
n- The the modulus value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.e- The exponent value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.d- The private exponent. It is represented as the Base64URL encoding of the value's big endian representation. 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.
-
RSAKey
public RSAKey(Base64URL n, Base64URL e, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by its first representation (see RFC 3447, section 3.2).- Parameters:
n- The the modulus value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.e- The exponent value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.d- The private exponent. It is represented as the Base64URL encoding of the value's big endian representation. 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.
-
RSAKey
@Deprecated public RSAKey(Base64URL n, Base64URL e, Base64URL p, Base64URL q, Base64URL dp, Base64URL dq, Base64URL qi, List<RSAKey.OtherPrimesInfo> oth, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by its second representation (see RFC 3447, section 3.2).- Parameters:
n- The the modulus value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.e- The exponent value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.p- The first prime factor. It is represented as the Base64URL encoding of the value's big endian representation. Must not benull.q- The second prime factor. It is represented as the Base64URL encoding of the value's big endian representation. Must not benull.dp- The first factor Chinese Remainder Theorem exponent. It is represented as the Base64URL encoding of the value's big endian representation. Must not benull.dq- The second factor Chinese Remainder Theorem exponent. It is represented as the Base64URL encoding of the value's big endian representation. Must not benull.qi- The first Chinese Remainder Theorem coefficient. It is represented as the Base64URL encoding of the value's big endian representation. Must not benull.oth- The other primes information, should they exist,nullor an empty list if not specified.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.
-
RSAKey
public RSAKey(Base64URL n, Base64URL e, Base64URL p, Base64URL q, Base64URL dp, Base64URL dq, Base64URL qi, List<RSAKey.OtherPrimesInfo> oth, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by its second representation (see RFC 3447, section 3.2).- Parameters:
n- The the modulus value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.e- The exponent value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.p- The first prime factor. It is represented as the Base64URL encoding of the value's big endian representation. Must not benull.q- The second prime factor. It is represented as the Base64URL encoding of the value's big endian representation. Must not benull.dp- The first factor Chinese Remainder Theorem exponent. It is represented as the Base64URL encoding of the value's big endian representation. Must not benull.dq- The second factor Chinese Remainder Theorem exponent. It is represented as the Base64URL encoding of the value's big endian representation. Must not benull.qi- The first Chinese Remainder Theorem coefficient. It is represented as the Base64URL encoding of the value's big endian representation. Must not benull.oth- The other primes information, should they exist,nullor an empty list if not specified.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.
-
RSAKey
@Deprecated public RSAKey(Base64URL n, Base64URL e, Base64URL d, Base64URL p, Base64URL q, Base64URL dp, Base64URL dq, Base64URL qi, List<RSAKey.OtherPrimesInfo> oth, KeyUse use, Set<KeyOperation> ops, Algorithm alg, String kid, URI x5u, Base64URL x5t, Base64URL x5t256, List<Base64> x5c) Deprecated.Creates a new public / private RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by both its first and second representations (see RFC 3447, section 3.2).A valid first private RSA key representation must specify the
dparameter.A valid second private RSA key representation must specify all required Chinese Remainder Theorem (CRT) parameters -
p,q,dp,dqandqi, else anIllegalArgumentExceptionwill be thrown.- Parameters:
n- The the modulus value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.e- The exponent value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.d- The private exponent. It is represented as the Base64URL encoding of the value's big endian representation. May benull.p- The first prime factor. It is represented as the Base64URL encoding of the value's big endian representation. May benull.q- The second prime factor. It is represented as the Base64URL encoding of the value's big endian representation. May benull.dp- The first factor Chinese Remainder Theorem exponent. It is represented as the Base64URL encoding of the value's big endian representation. May benull.dq- The second factor Chinese Remainder Theorem exponent. It is represented as the Base64URL encoding of the value's big endian representation. May benull.qi- The first Chinese Remainder Theorem coefficient. It is represented as the Base64URL encoding of the value's big endian representation. May benull.oth- The other primes information, should they exist,nullor an empty list if not specified.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.
-
RSAKey
@Deprecated public RSAKey(Base64URL n, Base64URL e, Base64URL d, Base64URL p, Base64URL q, Base64URL dp, Base64URL dq, Base64URL qi, List<RSAKey.OtherPrimesInfo> oth, PrivateKey prv, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key can be specified by its first representation, its second representation (see RFC 3447, section 3.2), or by a PKCS#11 handle asPrivateKey.A valid first private RSA key representation must specify the
dparameter.A valid second private RSA key representation must specify all required Chinese Remainder Theorem (CRT) parameters -
p,q,dp,dqandqi, else anIllegalArgumentExceptionwill be thrown.- Parameters:
n- The the modulus value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.e- The exponent value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.d- The private exponent. It is represented as the Base64URL encoding of the value's big endian representation. May benull.p- The first prime factor. It is represented as the Base64URL encoding of the value's big endian representation. May benull.q- The second prime factor. It is represented as the Base64URL encoding of the value's big endian representation. May benull.dp- The first factor Chinese Remainder Theorem exponent. It is represented as the Base64URL encoding of the value's big endian representation. May benull.dq- The second factor Chinese Remainder Theorem exponent. It is represented as the Base64URL encoding of the value's big endian representation. May benull.qi- The first Chinese Remainder Theorem coefficient. It is represented as the Base64URL encoding of the value's big endian representation. May benull.oth- The other primes information, should they exist,nullor an empty list if not specified.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.
-
RSAKey
public RSAKey(Base64URL n, Base64URL e, Base64URL d, Base64URL p, Base64URL q, Base64URL dp, Base64URL dq, Base64URL qi, List<RSAKey.OtherPrimesInfo> oth, PrivateKey prv, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key can be specified by its first representation, its second representation (see RFC 3447, section 3.2), or by a PKCS#11 handle asPrivateKey.A valid first private RSA key representation must specify the
dparameter.A valid second private RSA key representation must specify all required Chinese Remainder Theorem (CRT) parameters -
p,q,dp,dqandqi, else anIllegalArgumentExceptionwill be thrown.- Parameters:
n- The the modulus value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.e- The exponent value for the public RSA key. It is represented as the Base64URL encoding of value's big endian representation. Must not benull.d- The private exponent. It is represented as the Base64URL encoding of the value's big endian representation. May benull.p- The first prime factor. It is represented as the Base64URL encoding of the value's big endian representation. May benull.q- The second prime factor. It is represented as the Base64URL encoding of the value's big endian representation. May benull.dp- The first factor Chinese Remainder Theorem exponent. It is represented as the Base64URL encoding of the value's big endian representation. May benull.dq- The second factor Chinese Remainder Theorem exponent. It is represented as the Base64URL encoding of the value's big endian representation. May benull.qi- The first Chinese Remainder Theorem coefficient. It is represented as the Base64URL encoding of the value's big endian representation. May benull.oth- The other primes information, should they exist,nullor an empty list if not specified.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.
-
RSAKey
@Deprecated public RSAKey(RSAPublicKey pub, 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 RSA JSON Web Key (JWK) with the specified parameters.- Parameters:
pub- The public RSA key to represent. 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.
-
RSAKey
public RSAKey(RSAPublicKey pub, 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 RSA JSON Web Key (JWK) with the specified parameters.- Parameters:
pub- The public RSA key to represent. 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.
-
RSAKey
@Deprecated public RSAKey(RSAPublicKey pub, RSAPrivateKey priv, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by its first representation (see RFC 3447, section 3.2).- Parameters:
pub- The public RSA key to represent. Must not benull.priv- The private RSA key to represent. 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.
-
RSAKey
public RSAKey(RSAPublicKey pub, RSAPrivateKey priv, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by its first representation (see RFC 3447, section 3.2).- Parameters:
pub- The public RSA key to represent. Must not benull.priv- The private RSA key to represent. 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.
-
RSAKey
@Deprecated public RSAKey(RSAPublicKey pub, RSAPrivateCrtKey priv, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by its second representation (see RFC 3447, section 3.2).- Parameters:
pub- The public RSA key to represent. Must not benull.priv- The private RSA key to represent. 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.
-
RSAKey
public RSAKey(RSAPublicKey pub, RSAPrivateCrtKey priv, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by its second representation (see RFC 3447, section 3.2).- Parameters:
pub- The public RSA key to represent. Must not benull.priv- The private RSA key to represent. 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.
-
RSAKey
@Deprecated public RSAKey(RSAPublicKey pub, RSAMultiPrimePrivateCrtKey priv, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by its second representation, with optional other primes info (see RFC 3447, section 3.2).- Parameters:
pub- The public RSA key to represent. Must not benull.priv- The private RSA key to represent. 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.
-
RSAKey
public RSAKey(RSAPublicKey pub, RSAMultiPrimePrivateCrtKey priv, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by its second representation, with optional other primes info (see RFC 3447, section 3.2).- Parameters:
pub- The public RSA key to represent. Must not benull.priv- The private RSA key to represent. 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.
-
RSAKey
@Deprecated public RSAKey(RSAPublicKey pub, PrivateKey priv, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by a PKCS#11 handle.- Parameters:
pub- The public RSA key to represent. Must not benull.priv- The private RSA key as PKCS#11 handle,nullif not specified.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.
-
RSAKey
public RSAKey(RSAPublicKey pub, PrivateKey priv, 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 RSA JSON Web Key (JWK) with the specified parameters. The private RSA key is specified by a PKCS#11 handle.- Parameters:
pub- The public RSA key to represent. Must not benull.priv- The private RSA key as PKCS#11 handle,nullif not specified.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 Details
-
getModulus
Gets the modulus value (n) of the RSA key.- Returns:
- The RSA key modulus. It is represented as the Base64URL encoding of the value's big endian representation.
-
getPublicExponent
Gets the public exponent (e) of the RSA key.- Returns:
- The public RSA key exponent. It is represented as the Base64URL encoding of the value's big endian representation.
-
getPrivateExponent
Gets the private exponent (d) of the RSA key.- Returns:
- The private RSA key exponent. It is represented as the
Base64URL encoding of the value's big endian representation.
nullif not specified (for a public key or a private key using the second representation only).
-
getFirstPrimeFactor
Gets the first prime factor (p) of the private RSA key.- Returns:
- The RSA first prime factor. It is represented as the
Base64URL encoding of the value's big endian representation.
nullif not specified (for a public key or a private key using the first representation only).
-
getSecondPrimeFactor
Gets the second prime factor (q) of the private RSA key.- Returns:
- The RSA second prime factor. It is represented as the
Base64URL encoding of the value's big endian representation.
nullif not specified (for a public key or a private key using the first representation only).
-
getFirstFactorCRTExponent
Gets the first factor Chinese Remainder Theorem (CRT) exponent (dp) of the private RSA key.- Returns:
- The RSA first factor CRT exponent. It is represented as the
Base64URL encoding of the value's big endian representation.
nullif not specified (for a public key or a private key using the first representation only).
-
getSecondFactorCRTExponent
Gets the second factor Chinese Remainder Theorem (CRT) exponent (dq) of the private RSA key.- Returns:
- The RSA second factor CRT exponent. It is represented as the
Base64URL encoding of the value's big endian representation.
nullif not specified (for a public key or a private key using the first representation only).
-
getFirstCRTCoefficient
Gets the first Chinese Remainder Theorem (CRT) coefficient (qi)} of the private RSA key.- Returns:
- The RSA first CRT coefficient. It is represented as the
Base64URL encoding of the value's big endian representation.
nullif not specified (for a public key or a private key using the first representation only).
-
getOtherPrimes
Gets the other primes information (oth) for the private RSA key, should they exist.- Returns:
- The RSA other primes information,
nullor empty list if not specified.
-
toRSAPublicKey
Returns a standardjava.security.interfaces.RSAPublicKeyrepresentation of this RSA JWK.- Returns:
- The public RSA key.
- Throws:
JOSEException- If RSA is not supported by the underlying Java Cryptography (JCA) provider or if the JWK parameters are invalid for a public RSA key.
-
toRSAPrivateKey
Returns a standardjava.security.interfaces.RSAPrivateKeyrepresentation of this RSA JWK.- Returns:
- The private RSA key,
nullif not specified by this JWK. - Throws:
JOSEException- If RSA is not supported by the underlying Java Cryptography (JCA) provider or if the JWK parameters are invalid for a private RSA key.
-
toPublicKey
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
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
Returns a standardjava.security.KeyPairrepresentation of this RSA JWK.- Specified by:
toKeyPairin interfaceAsymmetricJWK- Returns:
- The RSA key pair. The private RSA key will be
nullif not specified. - Throws:
JOSEException- If RSA is not supported by the underlying Java Cryptography (JCA) provider or if the JWK parameters are invalid for a public and / or private RSA key.
-
matches
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
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
Description copied from class:JWKReturnstrueif this JWK contains private or sensitive (non-public) parameters. -
size
Description copied from class:JWKReturns the size of this JWK. -
toPublicJWK
Returns a copy of this RSA JWK with any private values removed.- Specified by:
toPublicJWKin classJWK- Returns:
- The copied public RSA JWK.
-
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
Parses a public / private RSA JWK from the specified JSON object string representation.- Parameters:
s- The JSON object string to parse. Must not benull.- Returns:
- The public / private RSA JWK.
- Throws:
ParseException- If the string couldn't be parsed to an RSA JWK.
-
parse
Parses a public / private RSA JWK from the specified JSON object representation.- Parameters:
jsonObject- The JSON object to parse. Must not benull.- Returns:
- The public / private RSA Key.
- Throws:
ParseException- If the JSON object couldn't be parsed to an RSA JWK.
-
parse
Parses a public RSA JWK from the specified X.509 certificate.Important: The X.509 certificate is not validated!
Sets the following JWK parameters:
- The JWK use inferred by
KeyUse.from(java.security.cert.X509Certificate). - The JWK ID from the X.509 serial number (in base 10).
- The JWK X.509 certificate chain (this certificate only).
- The JWK X.509 certificate SHA-256 thumbprint.
- Parameters:
cert- The X.509 certificate. Must not benull.- Returns:
- The public RSA key.
- Throws:
JOSEException- If parsing failed.
- The JWK use inferred by
-
load
public static RSAKey load(KeyStore keyStore, String alias, char[] pin) throws KeyStoreException, JOSEException Loads a public / private RSA JWK from the specified JCA key store.Important: The X.509 certificate is not validated!
- Parameters:
keyStore- The key store. Must not benull.alias- The alias. Must not benull.pin- The pin to unlock the private key if any, empty ornullif not required.- Returns:
- The public / private RSA key,
nullif no key with the specified alias was found. - Throws:
KeyStoreException- On a key store exception.JOSEException- If RSA key loading failed.
-
equals
-
hashCode
-