Jwts.SIG
instead.@Deprecated public enum SignatureAlgorithm extends Enum<SignatureAlgorithm>
Enum Constant and Description |
---|
ES256
Deprecated.
JWA algorithm name for
ECDSA using P-256 and SHA-256 |
ES384
Deprecated.
JWA algorithm name for
ECDSA using P-384 and SHA-384 |
ES512
Deprecated.
JWA algorithm name for
ECDSA using P-521 and SHA-512 |
HS256
Deprecated.
JWA algorithm name for
HMAC using SHA-256 |
HS384
Deprecated.
JWA algorithm name for
HMAC using SHA-384 |
HS512
Deprecated.
JWA algorithm name for
HMAC using SHA-512 |
NONE
Deprecated.
JWA name for
No digital signature or MAC performed |
PS256
Deprecated.
JWA algorithm name for
RSASSA-PSS using SHA-256 and MGF1 with SHA-256 . |
PS384
Deprecated.
JWA algorithm name for
RSASSA-PSS using SHA-384 and MGF1 with SHA-384 . |
PS512
Deprecated.
JWA algorithm name for
RSASSA-PSS using SHA-512 and MGF1 with SHA-512 . |
RS256
Deprecated.
JWA algorithm name for
RSASSA-PKCS-v1_5 using SHA-256 |
RS384
Deprecated.
JWA algorithm name for
RSASSA-PKCS-v1_5 using SHA-384 |
RS512
Deprecated.
JWA algorithm name for
RSASSA-PKCS-v1_5 using SHA-512 |
Modifier and Type | Method and Description |
---|---|
void |
assertValidSigningKey(Key key)
Deprecated.
Returns quietly if the specified key is allowed to create signatures using this algorithm
according to the JWT JWA Specification (RFC 7518) or throws an
InvalidKeyException if the key is not allowed or not secure enough for this algorithm. |
void |
assertValidVerificationKey(Key key)
Deprecated.
Returns quietly if the specified key is allowed to verify signatures using this algorithm
according to the JWT JWA Specification (RFC 7518) or throws an
InvalidKeyException if the key is not allowed or not secure enough for this algorithm. |
static SignatureAlgorithm |
forName(String value)
Deprecated.
Looks up and returns the corresponding
SignatureAlgorithm enum instance based on a
case-insensitive name comparison. |
static SignatureAlgorithm |
forSigningKey(Key key)
Deprecated.
Returns the recommended signature algorithm to be used with the specified key according to the following
heuristics:
SecretKey
1
256 <= size <= 383 2
HS256
SecretKey
1
384 <= size <= 511
HS384
SecretKey
1
512 <= size
HS512
ECKey
instanceof
256 <= size <= 383 3
ES256
ECKey
instanceof
384 <= size <= 511
ES384
ECKey
instanceof
4096 <= size
ES512
RSAKey
instanceof
2048 <= size <= 3071 4,5
RS256
RSAKey
instanceof
3072 <= size <= 4095 5
RS384
RSAKey
instanceof
4096 <= size 5
RS512
|
String |
getDescription()
Deprecated.
Returns the JWA algorithm description.
|
String |
getFamilyName()
Deprecated.
Returns the cryptographic family name of the signature algorithm.
|
String |
getJcaName()
Deprecated.
Returns the name of the JCA algorithm used to compute the signature.
|
int |
getMinKeyLength()
Deprecated.
Returns the minimum key length in bits (not bytes) that may be used with this algorithm according to the
JWT JWA Specification (RFC 7518).
|
String |
getValue()
Deprecated.
Returns the JWA algorithm name constant.
|
boolean |
isEllipticCurve()
Deprecated.
Returns
true if the enum instance represents an Elliptic Curve ECDSA signature algorithm, false
otherwise. |
boolean |
isHmac()
Deprecated.
Returns
true if the enum instance represents an HMAC signature algorithm, false otherwise. |
boolean |
isJdkStandard()
Deprecated.
Returns
true if the algorithm is supported by standard JDK distributions or false if the
algorithm implementation is not in the JDK and must be provided by a separate runtime JCA Provider (like
BouncyCastle for example). |
boolean |
isRsa()
Deprecated.
Returns
true if the enum instance represents an RSA public/private key pair signature algorithm,
false otherwise. |
static SignatureAlgorithm |
valueOf(String name)
Deprecated.
Returns the enum constant of this type with the specified name.
|
static SignatureAlgorithm[] |
values()
Deprecated.
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final SignatureAlgorithm NONE
No digital signature or MAC performed
public static final SignatureAlgorithm HS256
HMAC using SHA-256
public static final SignatureAlgorithm HS384
HMAC using SHA-384
public static final SignatureAlgorithm HS512
HMAC using SHA-512
public static final SignatureAlgorithm RS256
RSASSA-PKCS-v1_5 using SHA-256
public static final SignatureAlgorithm RS384
RSASSA-PKCS-v1_5 using SHA-384
public static final SignatureAlgorithm RS512
RSASSA-PKCS-v1_5 using SHA-512
public static final SignatureAlgorithm ES256
ECDSA using P-256 and SHA-256
public static final SignatureAlgorithm ES384
ECDSA using P-384 and SHA-384
public static final SignatureAlgorithm ES512
ECDSA using P-521 and SHA-512
public static final SignatureAlgorithm PS256
RSASSA-PSS using SHA-256 and MGF1 with SHA-256
. This algorithm requires
Java 11 or later or a JCA provider like BouncyCastle to be in the runtime classpath. If on Java 10 or
earlier, BouncyCastle will be used automatically if found in the runtime classpath.public static final SignatureAlgorithm PS384
RSASSA-PSS using SHA-384 and MGF1 with SHA-384
. This algorithm requires
Java 11 or later or a JCA provider like BouncyCastle to be in the runtime classpath. If on Java 10 or
earlier, BouncyCastle will be used automatically if found in the runtime classpath.public static final SignatureAlgorithm PS512
RSASSA-PSS using SHA-512 and MGF1 with SHA-512
. This algorithm requires
Java 11 or later or a JCA provider like BouncyCastle to be in the runtime classpath. If on Java 10 or
earlier, BouncyCastle will be used automatically if found in the runtime classpath.public static SignatureAlgorithm[] values()
for (SignatureAlgorithm c : SignatureAlgorithm.values()) System.out.println(c);
public static SignatureAlgorithm valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic String getValue()
public String getDescription()
public String getFamilyName()
SignatureAlgorithm | Family Name |
---|---|
HS256 | HMAC |
HS384 | HMAC |
HS512 | HMAC |
RS256 | RSA |
RS384 | RSA |
RS512 | RSA |
PS256 | RSA |
PS384 | RSA |
PS512 | RSA |
ES256 | ECDSA |
ES384 | ECDSA |
ES512 | ECDSA |
public String getJcaName()
public boolean isJdkStandard()
true
if the algorithm is supported by standard JDK distributions or false
if the
algorithm implementation is not in the JDK and must be provided by a separate runtime JCA Provider (like
BouncyCastle for example).true
if the algorithm is supported by standard JDK distributions or false
if the
algorithm implementation is not in the JDK and must be provided by a separate runtime JCA Provider (like
BouncyCastle for example).public boolean isHmac()
true
if the enum instance represents an HMAC signature algorithm, false
otherwise.true
if the enum instance represents an HMAC signature algorithm, false
otherwise.public boolean isRsa()
true
if the enum instance represents an RSA public/private key pair signature algorithm,
false
otherwise.true
if the enum instance represents an RSA public/private key pair signature algorithm,
false
otherwise.public boolean isEllipticCurve()
true
if the enum instance represents an Elliptic Curve ECDSA signature algorithm, false
otherwise.true
if the enum instance represents an Elliptic Curve ECDSA signature algorithm, false
otherwise.public int getMinKeyLength()
public void assertValidSigningKey(Key key) throws InvalidKeyException
InvalidKeyException
if the key is not allowed or not secure enough for this algorithm.key
- the key to check for validity.InvalidKeyException
- if the key is not allowed or not secure enough for this algorithm.public void assertValidVerificationKey(Key key) throws InvalidKeyException
InvalidKeyException
if the key is not allowed or not secure enough for this algorithm.key
- the key to check for validity.InvalidKeyException
- if the key is not allowed or not secure enough for this algorithm.public static SignatureAlgorithm forSigningKey(Key key) throws InvalidKeyException
If the Key is a: | And: | With a key size of: | The returned SignatureAlgorithm will be: |
---|---|---|---|
SecretKey |
1 |
256 <= size <= 383 2 | HS256 |
SecretKey |
1 |
384 <= size <= 511 | HS384 |
SecretKey |
1 |
512 <= size | HS512 |
ECKey |
instanceof |
256 <= size <= 383 3 | ES256 |
ECKey |
instanceof |
384 <= size <= 511 | ES384 |
ECKey |
instanceof |
4096 <= size | ES512 |
RSAKey |
instanceof |
2048 <= size <= 3071 4,5 | RS256 |
RSAKey |
instanceof |
3072 <= size <= 4095 5 | RS384 |
RSAKey |
instanceof |
4096 <= size 5 | RS512 |
Notes:
SecretKey
instances must have an algorithm
name equal
to HmacSHA256
, HmacSHA384
or HmacSHA512
. If not, the key bytes might not be
suitable for HMAC signatures will be rejected with a InvalidKeyException
. SecretKey
s with key lengths less than 256 bits will be rejected with an
WeakKeyException
.ECKey
s with key lengths less than 256 bits will be rejected with a
WeakKeyException
.RSAKey
s with key lengths less than 2048 bits will be rejected with a
WeakKeyException
.RS256
, RS384
, and
RS512
algorithms, so we assume an RSA signature algorithm based on the key length to
parallel similar decisions in the JWT specification for HMAC and ECDSA signature algorithms.
This is not required - just a convenience.This implementation does not return the PS256
, PS256
, PS256
RSA variant for any
specified RSAKey
because:
RS256
, RS384
, and RS512
are
recommended algorithms while the PS
* variants are simply marked as optional.RS256
, RS384
, and RS512
algorithms are available in the JDK by default
while the PS
* variants require an additional JCA Provider (like BouncyCastle).Finally, this method will throw an InvalidKeyException
for any key that does not match the
heuristics and requirements documented above, since that inevitably means the Key is either insufficient or
explicitly disallowed by the JWT specification.
key
- the key to inspectInvalidKeyException
- for any key that does not match the heuristics and requirements documented above,
since that inevitably means the Key is either insufficient or explicitly disallowed by the JWT specification.public static SignatureAlgorithm forName(String value) throws SignatureException
SignatureAlgorithm
enum instance based on a
case-insensitive name comparison.value
- The case-insensitive name of the SignatureAlgorithm
instance to returnSignatureAlgorithm
enum instance based on a
case-insensitive name comparison.SignatureException
- if the specified value does not match any SignatureAlgorithm
name.SignatureException
Copyright © 2014–2024 jsonwebtoken.io. All rights reserved.