public abstract class EllipticCurveProvider
extends java.lang.Object
限定符和类型 | 字段和说明 |
---|---|
protected SignatureAlgorithm |
alg |
static java.security.SecureRandom |
DEFAULT_SECURE_RANDOM
JJWT's default SecureRandom number generator.
|
protected java.security.Key |
key |
限定符 | 构造器和说明 |
---|---|
protected |
EllipticCurveProvider(SignatureAlgorithm alg,
java.security.Key key) |
限定符和类型 | 方法和说明 |
---|---|
protected java.security.Signature |
createSignatureInstance() |
static java.security.KeyPair |
generateKeyPair()
Generates a new secure-random key pair assuming strength enough for the
SignatureAlgorithm.ES512 algorithm. |
static java.security.KeyPair |
generateKeyPair(SignatureAlgorithm alg)
Generates a new secure-random key pair of sufficient strength for the specified Elliptic Curve
SignatureAlgorithm (must be one of ES256 , ES384 or ES512 ) using JJWT's default SecureRandom instance . |
static java.security.KeyPair |
generateKeyPair(SignatureAlgorithm alg,
java.security.SecureRandom random)
Generates a new secure-random key pair of sufficient strength for the specified Elliptic Curve
SignatureAlgorithm (must be one of ES256 , ES384 or ES512 ) using the specified SecureRandom random number generator. |
static java.security.KeyPair |
generateKeyPair(java.lang.String jcaAlgorithmName,
java.lang.String jcaProviderName,
SignatureAlgorithm alg,
java.security.SecureRandom random)
Generates a new secure-random key pair of sufficient strength for the specified Elliptic Curve
SignatureAlgorithm (must be one of ES256 , ES384 or ES512 ) using the specified SecureRandom random number generator via the specified JCA provider and algorithm name. |
static int |
getSignatureByteArrayLength(SignatureAlgorithm alg)
Returns the expected signature byte array length (R + S parts) for
the specified ECDSA algorithm.
|
protected java.security.Signature |
getSignatureInstance() |
protected boolean |
isBouncyCastleAvailable() |
static byte[] |
transcodeSignatureToConcat(byte[] derSignature,
int outputLength)
Transcodes the JCA ASN.1/DER-encoded signature into the concatenated
R + S format expected by ECDSA JWS.
|
static byte[] |
transcodeSignatureToDER(byte[] jwsSignature)
Transcodes the ECDSA JWS signature into ASN.1/DER format for use by
the JCA verifier.
|
public static final java.security.SecureRandom DEFAULT_SECURE_RANDOM
static {
DEFAULT_SECURE_RANDOM = new SecureRandom();
DEFAULT_SECURE_RANDOM.nextBytes(new byte[64]);
}
nextBytes
is called to force the RNG to initialize itself if not already initialized. The
byte array is not used and discarded immediately for garbage collection.
protected final SignatureAlgorithm alg
protected final java.security.Key key
protected EllipticCurveProvider(SignatureAlgorithm alg, java.security.Key key)
public static java.security.KeyPair generateKeyPair()
SignatureAlgorithm.ES512
algorithm. This is a convenience method that immediately delegates to generateKeyPair(SignatureAlgorithm)
using SignatureAlgorithm.ES512
as the method argument.SignatureAlgorithm.ES512
algorithm.generateKeyPair(SignatureAlgorithm)
,
generateKeyPair(SignatureAlgorithm, SecureRandom)
,
generateKeyPair(String, String, SignatureAlgorithm, SecureRandom)
public static java.security.KeyPair generateKeyPair(SignatureAlgorithm alg)
SignatureAlgorithm
(must be one of ES256
, ES384
or ES512
) using JJWT's default SecureRandom instance
. This is a convenience method that immediately
delegates to generateKeyPair(SignatureAlgorithm, SecureRandom)
.alg
- the algorithm indicating strength, must be one of ES256
, ES384
or ES512
SignatureAlgorithm
(must be one of ES256
, ES384
or ES512
) using JJWT's default SecureRandom instance
.generateKeyPair()
,
generateKeyPair(SignatureAlgorithm, SecureRandom)
,
generateKeyPair(String, String, SignatureAlgorithm, SecureRandom)
public static java.security.KeyPair generateKeyPair(SignatureAlgorithm alg, java.security.SecureRandom random)
SignatureAlgorithm
(must be one of ES256
, ES384
or ES512
) using the specified SecureRandom
random number generator. This is a convenience method that immediately delegates to generateKeyPair(String, String, SignatureAlgorithm, SecureRandom)
using "ECDSA"
as the jcaAlgorithmName
and "BC"
as the jcaProviderName
since EllipticCurve requires the use of an
external JCA provider (BC stands for BouncyCastle
. This will work as expected as long as the
BouncyCastle dependency is in the runtime classpath.alg
- alg the algorithm indicating strength, must be one of ES256
, ES384
or ES512
random
- the SecureRandom generator to use during key generation.SignatureAlgorithm
(must be one of ES256
, ES384
or ES512
) using the specified SecureRandom
random number generator.generateKeyPair()
,
generateKeyPair(SignatureAlgorithm)
,
generateKeyPair(String, String, SignatureAlgorithm, SecureRandom)
public static java.security.KeyPair generateKeyPair(java.lang.String jcaAlgorithmName, java.lang.String jcaProviderName, SignatureAlgorithm alg, java.security.SecureRandom random)
SignatureAlgorithm
(must be one of ES256
, ES384
or ES512
) using the specified SecureRandom
random number generator via the specified JCA provider and algorithm name.jcaAlgorithmName
- the JCA name of the algorithm to use for key pair generation, for example, ECDSA
.jcaProviderName
- the JCA provider name of the algorithm implementation, for example BC
for
BouncyCastle.alg
- alg the algorithm indicating strength, must be one of ES256
, ES384
or
ES512
random
- the SecureRandom generator to use during key generation.SignatureAlgorithm
(must be one of ES256
, ES384
or ES512
) using the specified SecureRandom
random number generator via the specified JCA provider and algorithm name.generateKeyPair()
,
generateKeyPair(SignatureAlgorithm)
,
generateKeyPair(SignatureAlgorithm, SecureRandom)
public static int getSignatureByteArrayLength(SignatureAlgorithm alg) throws JwtException
alg
- The ECDSA algorithm. Must be supported and not
null
.JwtException
- If the algorithm is not supported.public static byte[] transcodeSignatureToConcat(byte[] derSignature, int outputLength) throws JwtException
derSignature
- The ASN1./DER-encoded. Must not be null
.outputLength
- The expected length of the ECDSA JWS signature.JwtException
- If the ASN.1/DER signature format is invalid.public static byte[] transcodeSignatureToDER(byte[] jwsSignature) throws JwtException
jwsSignature
- The JWS signature, consisting of the
concatenated R and S values. Must not be
null
.JwtException
- If the ECDSA JWS signature format is invalid.protected java.security.Signature createSignatureInstance()
protected java.security.Signature getSignatureInstance() throws java.security.NoSuchAlgorithmException
java.security.NoSuchAlgorithmException
protected boolean isBouncyCastleAvailable()