public class HmacSigningHandler extends Object implements SigningHandler
Constructor and Description |
---|
HmacSigningHandler(byte[] sharedSecret)
Constructs a new HmacSigningHandler.
|
HmacSigningHandler(SecretKey key)
Constructs a new HmacSigningHandler.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
sign(JwsAlgorithm algorithm,
byte[] data)
Signs the given raw data bytes using the Java Cryptographic algorithm defined by the JwsAlgorithm.
|
byte[] |
sign(JwsAlgorithm algorithm,
String data)
Signs the given String data using the Java Cryptographic algorithm defined by the JwsAlgorithm.
|
boolean |
verify(JwsAlgorithm algorithm,
byte[] data,
byte[] signature)
Verifies that the given signature is valid for the given data.
|
public HmacSigningHandler(byte[] sharedSecret)
sharedSecret
- The shared secret to use to sign the data.public HmacSigningHandler(SecretKey key)
key
- The HMAC secret key to use to sign the data.public byte[] sign(JwsAlgorithm algorithm, String data)
sign
in interface SigningHandler
algorithm
- The JwsAlgorithm defining the Java Cryptographic algorithm.data
- The data to be signed.public byte[] sign(JwsAlgorithm algorithm, byte[] data)
sign
in interface SigningHandler
algorithm
- the JWS signature algorithm to use.data
- the raw data to sign.public boolean verify(JwsAlgorithm algorithm, byte[] data, byte[] signature)
Uses the Java Cryptographic algorithm defined by the JwsAlgorithm and private key to create a new signature of the data to compare against the given signature to see if they are identical. This implementation avoids timing attacks by enforcing checking of each element of the array against one another. We do not rely on Arrays.equal or other methods which may return early upon discovering a mistake.
verify
in interface SigningHandler
algorithm
- The JwsAlgorithm defining the JavaCryptographic algorithm.data
- The data that was signed.signature
- The signature of the data.true
if the signature is a valid signature of the data.Copyright 2010-2022 ForgeRock AS.