| Modifier and Type | Field and Description |
|---|---|
protected SignatureAlgorithm |
alg |
static SecureRandom |
DEFAULT_SECURE_RANDOM
JJWT's default SecureRandom number generator.
|
protected Key |
key |
| Modifier | Constructor and Description |
|---|---|
protected |
MacProvider(SignatureAlgorithm alg,
Key key) |
| Modifier and Type | Method and Description |
|---|---|
protected Signature |
createSignatureInstance() |
static SecretKey |
generateKey()
Generates a new secure-random 512 bit secret key suitable for creating and verifying HMAC-SHA signatures.
|
static 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 SecretKey |
generateKey(SignatureAlgorithm alg,
SecureRandom random)
Deprecated.
since 0.10.0 - use
generateKey(SignatureAlgorithm) instead. |
protected Signature |
getSignatureInstance() |
protected boolean |
isBouncyCastleAvailable() |
public static final 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 Key key
protected MacProvider(SignatureAlgorithm alg, Key key)
public static SecretKey generateKey()
generateKey(SignatureAlgorithm) using SignatureAlgorithm.HS512 as the method argument.generateKey(SignatureAlgorithm),
generateKey(SignatureAlgorithm, SecureRandom)public static 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)@Deprecated public static SecretKey generateKey(SignatureAlgorithm alg, SecureRandom random)
generateKey(SignatureAlgorithm) instead.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 Signature createSignatureInstance()
protected Signature getSignatureInstance() throws NoSuchAlgorithmException
NoSuchAlgorithmExceptionprotected boolean isBouncyCastleAvailable()
Copyright © 2020. All rights reserved.