Package com.nimbusds.jose.jwk
Class RSAKey.Builder
java.lang.Object
com.nimbusds.jose.jwk.RSAKey.Builder
- Enclosing class:
- RSAKey
Builder for constructing RSA JWKs.
Example usage:
RSAKey key = new RSAKey.Builder(n, e). privateExponent(d). algorithm(JWSAlgorithm.RS512). keyID("456"). build();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets the intended JOSE algorithm (alg
) for the JWK.build()
Builds a new RSA JWK.expirationTime
(Date exp) Sets the expiration time (exp
) of the JWK.Sets the first Chinese Remainder Theorem (CRT) coefficient (qi
) of the private RSA key.Sets the first factor Chinese Remainder Theorem (CRT) exponent (dp
) of the private RSA key.Sets the first prime factor (p
) of the private RSA key.Sets the issued-at time (iat
) of the JWK.Sets the ID (kid
) of the JWK.Sets the ID (kid
) of the JWK to its SHA-256 JWK thumbprint (RFC 7638).keyIDFromThumbprint
(String hashAlg) Sets the ID (kid
) of the JWK to its JWK thumbprint (RFC 7638).keyOperations
(Set<KeyOperation> ops) Sets the operations (key_ops
) of the JWK (for a non-public key).keyRevocation
(KeyRevocation revocation) Sets the revocation (revoked
) of the JWK.Sets the underlying key store.Sets the use (use
) of the JWK.notBeforeTime
(Date nbf) Sets the not-before time (nbf
) of the JWK.Sets the other primes information (oth
) for the private RSA key, should they exist.Sets the private exponent (d
) of the RSA key.Sets the private RSA key, using the second representation, with optional other primes info (see RFC 3447, section 3.2).privateKey
(RSAPrivateCrtKey priv) Sets the private RSA key, using the second representation (see RFC 3447, section 3.2).privateKey
(RSAPrivateKey priv) Sets the private RSA key, using the first representation.privateKey
(PrivateKey priv) Sets the private RSA key, typically for a key located in a PKCS#11 store that doesn't expose the private key parameters (such as a smart card or HSM).Sets the second factor Chinese Remainder Theorem (CRT) exponent (dq
) of the private RSA key.Sets the second prime factor (q
) of the private RSA key.x509CertChain
(List<Base64> x5c) Sets the X.509 certificate chain (x5c
) of the JWK.x509CertSHA256Thumbprint
(Base64URL x5t256) Sets the X.509 certificate SHA-256 thumbprint (x5t#S256
) of the JWK.Deprecated.x509CertURL
(URI x5u) Sets the X.509 certificate URL (x5u
) of the JWK.
-
Constructor Details
-
Builder
Creates a new RSA JWK builder.- Parameters:
n
- 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
.
-
Builder
Creates a new RSA JWK builder.- Parameters:
pub
- The public RSA key to represent. Must not benull
.
-
Builder
Creates a new RSA JWK builder.- Parameters:
rsaJWK
- The RSA JWK to start with. Must not benull
.
-
-
Method Details
-
privateExponent
Sets the private exponent (d
) of the RSA key.- Parameters:
d
- The private RSA key exponent. It is represented as the Base64URL encoding of the value's big endian representation.null
if not specified (for a public key or a private key specified otherwise).- Returns:
- This builder.
-
privateKey
Sets the private RSA key, using the first representation.- Parameters:
priv
- The private RSA key, used to obtain the private exponent (d
).null
if not specified (for a public key or a private key specified otherwise).- Returns:
- This builder.
-
privateKey
Sets the private RSA key, typically for a key located in a PKCS#11 store that doesn't expose the private key parameters (such as a smart card or HSM).- Parameters:
priv
- The private RSA key reference. Its algorithm must be "RSA".null
if not specified (for a public key or private key specified otherwise).- Returns:
- This builder.
-
firstPrimeFactor
Sets the first prime factor (p
) of the private RSA key.- Parameters:
p
- The RSA first prime factor. It is represented as the Base64URL encoding of the value's big endian representation.null
if not specified (for a public key or a private key specified otherwise).- Returns:
- This builder.
-
secondPrimeFactor
Sets the second prime factor (q
) of the private RSA key.- Parameters:
q
- The RSA second prime factor. It is represented as the Base64URL encoding of the value's big endian representation.null
if not specified (for a public key or a private specified otherwise).- Returns:
- This builder.
-
firstFactorCRTExponent
Sets the first factor Chinese Remainder Theorem (CRT) exponent (dp
) of the private RSA key.- Parameters:
dp
- The RSA first factor CRT exponent. It is represented as the Base64URL encoding of the value's big endian representation.null
if not specified (for a public key or a private key specified otherwise).- Returns:
- This builder.
-
secondFactorCRTExponent
Sets the second factor Chinese Remainder Theorem (CRT) exponent (dq
) of the private RSA key.- Parameters:
dq
- The RSA second factor CRT exponent. It is represented as the Base64URL encoding of the value's big endian representation.null
if not specified (for a public key or a private key specified otherwise).- Returns:
- This builder.
-
firstCRTCoefficient
Sets the first Chinese Remainder Theorem (CRT) coefficient (qi
) of the private RSA key.- Parameters:
qi
- The RSA first CRT coefficient. It is represented as the Base64URL encoding of the value's big endian representation.null
if not specified (for a public key or a private key specified otherwise).- Returns:
- This builder.
-
otherPrimes
Sets the other primes information (oth
) for the private RSA key, should they exist.- Parameters:
oth
- The RSA other primes information,null
or empty list if not specified.- Returns:
- This builder.
-
privateKey
Sets the private RSA key, using the second representation (see RFC 3447, section 3.2).- Parameters:
priv
- The private RSA key, used to obtain the private exponent (d
), the first prime factor (p
), the second prime factor (q
), the first factor CRT exponent (dp
), the second factor CRT exponent (dq
) and the first CRT coefficient (qi
).null
if not specified (for a public key or private key specified otherwise).- Returns:
- This builder.
-
privateKey
Sets the private RSA key, using the second representation, with optional other primes info (see RFC 3447, section 3.2).- Parameters:
priv
- The private RSA key, used to obtain the private exponent (d
), the first prime factor (p
), the second prime factor (q
), the first factor CRT exponent (dp
), the second factor CRT exponent (dq
), the first CRT coefficient (qi
) and the other primes info (oth
).null
if not specified (for a public key or private key specified otherwise).- Returns:
- This builder.
-
keyUse
Sets the use (use
) of the JWK.- Parameters:
use
- The key use,null
if not specified or if the key is intended for signing as well as encryption.- Returns:
- This builder.
-
keyOperations
Sets the operations (key_ops
) of the JWK (for a non-public key).- Parameters:
ops
- The key operations,null
if not specified.- Returns:
- This builder.
-
algorithm
Sets the intended JOSE algorithm (alg
) for the JWK.- Parameters:
alg
- The intended JOSE algorithm,null
if not specified.- Returns:
- This builder.
-
keyID
Sets the ID (kid
) of the JWK. The key ID can be used to match a specific key. This can be used, for instance, to choose a key within aJWKSet
during key rollover. The key ID may also correspond to a JWS/JWEkid
header parameter value.- Parameters:
kid
- The key ID,null
if not specified.- Returns:
- This builder.
-
keyIDFromThumbprint
Sets the ID (kid
) of the JWK to its SHA-256 JWK thumbprint (RFC 7638). The key ID can be used to match a specific key. This can be used, for instance, to choose a key within aJWKSet
during key rollover. The key ID may also correspond to a JWS/JWEkid
header parameter value.- Returns:
- This builder.
- Throws:
JOSEException
- If the SHA-256 hash algorithm is not supported.
-
keyIDFromThumbprint
Sets the ID (kid
) of the JWK to its JWK thumbprint (RFC 7638). The key ID can be used to match a specific key. This can be used, for instance, to choose a key within aJWKSet
during key rollover. The key ID may also correspond to a JWS/JWEkid
header parameter value.- Parameters:
hashAlg
- The hash algorithm for the JWK thumbprint computation. Must not benull
.- Returns:
- This builder.
- Throws:
JOSEException
- If the hash algorithm is not supported.
-
x509CertURL
Sets the X.509 certificate URL (x5u
) of the JWK.- Parameters:
x5u
- The X.509 certificate URL,null
if not specified.- Returns:
- This builder.
-
x509CertThumbprint
Deprecated.Sets the X.509 certificate SHA-1 thumbprint (x5t
) of the JWK.- Parameters:
x5t
- The X.509 certificate SHA-1 thumbprint,null
if not specified.- Returns:
- This builder.
-
x509CertSHA256Thumbprint
Sets the X.509 certificate SHA-256 thumbprint (x5t#S256
) of the JWK.- Parameters:
x5t256
- The X.509 certificate SHA-256 thumbprint,null
if not specified.- Returns:
- This builder.
-
x509CertChain
Sets the X.509 certificate chain (x5c
) of the JWK.- Parameters:
x5c
- The X.509 certificate chain as a unmodifiable list,null
if not specified.- Returns:
- This builder.
-
expirationTime
Sets the expiration time (exp
) of the JWK.- Parameters:
exp
- The expiration time,null
if not specified.- Returns:
- This builder.
-
notBeforeTime
Sets the not-before time (nbf
) of the JWK.- Parameters:
nbf
- The not-before time,null
if not specified.- Returns:
- This builder.
-
issueTime
Sets the issued-at time (iat
) of the JWK.- Parameters:
iat
- The issued-at time,null
if not specified.- Returns:
- This builder.
-
keyRevocation
Sets the revocation (revoked
) of the JWK.- Parameters:
revocation
- The key revocation,null
if not specified.- Returns:
- This builder.
-
keyStore
Sets the underlying key store.- Parameters:
keyStore
- Reference to the underlying key store,null
if none.- Returns:
- This builder.
-
build
Builds a new RSA JWK.- Returns:
- The RSA JWK.
- Throws:
IllegalStateException
- If the JWK parameters were inconsistently specified.
-