public abstract class MacProvider
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 |
MacProvider(SignatureAlgorithm alg,
java.security.Key key) |
限定符和类型 | 方法和说明 |
---|---|
protected java.security.Signature |
createSignatureInstance() |
static javax.crypto.SecretKey |
generateKey()
Generates a new secure-random 512 bit secret key suitable for creating and verifying HMAC signatures.
|
static javax.crypto.SecretKey |
generateKey(SignatureAlgorithm alg)
Generates a new secure-random secret key of a length suitable for creating and verifying HMAC signatures
according to the specified
SignatureAlgorithm using JJWT's default SecureRandom instance . |
static javax.crypto.SecretKey |
generateKey(SignatureAlgorithm alg,
java.security.SecureRandom random)
Generates a new secure-random secret key of a length suitable for creating and verifying HMAC signatures
according to the specified
SignatureAlgorithm using the specified SecureRandom number generator. |
protected java.security.Signature |
getSignatureInstance() |
protected boolean |
isBouncyCastleAvailable() |
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 MacProvider(SignatureAlgorithm alg, java.security.Key key)
public static javax.crypto.SecretKey generateKey()
generateKey(SignatureAlgorithm)
using SignatureAlgorithm.HS512
as the method argument.generateKey(SignatureAlgorithm)
,
generateKey(SignatureAlgorithm, SecureRandom)
public static javax.crypto.SecretKey generateKey(SignatureAlgorithm alg)
SignatureAlgorithm
using JJWT's default SecureRandom instance
. This is a convenience method that immediately
delegates to generateKey(SignatureAlgorithm, SecureRandom)
.alg
- the desired signature algorithmSignatureAlgorithm
using JJWT's default SecureRandom instance
.generateKey()
,
generateKey(SignatureAlgorithm, SecureRandom)
public static javax.crypto.SecretKey generateKey(SignatureAlgorithm alg, java.security.SecureRandom random)
SignatureAlgorithm
using the specified SecureRandom number generator. This
implementation returns secure-random key sizes as follows:
Signature Algorithm | Generated Key Size |
---|---|
HS256 | 256 bits (32 bytes) |
HS384 | 384 bits (48 bytes) |
HS512 | 512 bits (64 bytes) |
alg
- the signature algorithm that will be used with the generated keyrandom
- the secure random number generator used during key generationSignatureAlgorithm
using the specified SecureRandom number generator.generateKey()
,
generateKey(SignatureAlgorithm)
protected java.security.Signature createSignatureInstance()
protected java.security.Signature getSignatureInstance() throws java.security.NoSuchAlgorithmException
java.security.NoSuchAlgorithmException
protected boolean isBouncyCastleAvailable()