public class MacHelper extends Object
MacAlgorithm.DEFAULT
(HMACSHA384). Under the hood the Mac
class is used.Constructor and Description |
---|
MacHelper()
Default constructor that creates a helper that uses
MacAlgorithm.DEFAULT (HMACSHA384). |
MacHelper(MacAlgorithm algorithm)
Constructor that creates a helper that uses the provided algorithm.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
digest(SecretKey key,
byte[] data)
Creates the message digest using the helpers algorithm for the given data using the given key.
|
SecretKey |
generateKey()
This generates a new
SecretKey using the helpers MacAlgorithm . |
SecretKey |
generateKey(byte[] encodedKey)
This generates a
SecretKey from the given key bytes using the helpers MacAlgorithm . |
boolean |
verify(SecretKey key,
byte[] data,
byte[] digest)
This will check to see if the passed in digest matches the digest created from the passed in key and data.
|
public MacHelper() throws NoSuchAlgorithmException
MacAlgorithm.DEFAULT
(HMACSHA384).NoSuchAlgorithmException
- thrown if the HMACSHA384 algorithm is not supportedpublic MacHelper(MacAlgorithm algorithm) throws NoSuchAlgorithmException
algorithm
- the algorithm this helper will useNoSuchAlgorithmException
- thrown if the algorithm is not supportedpublic byte[] digest(SecretKey key, byte[] data) throws InvalidKeyException
key
- the key to generate the digest withdata
- the data to generate the digest withInvalidKeyException
- thrown is the key is not the correct formatpublic SecretKey generateKey(byte[] encodedKey)
SecretKey
from the given key bytes using the helpers MacAlgorithm
.encodedKey
- the HMAC key encoded bytespublic SecretKey generateKey() throws NoSuchAlgorithmException
SecretKey
using the helpers MacAlgorithm
.NoSuchAlgorithmException
- thrown if the helpers algorithm is not supportedpublic boolean verify(SecretKey key, byte[] data, byte[] digest) throws InvalidKeyException
digest(SecretKey, byte[])
method. That method will use
the MacAlgorithm
defined for this helper.key
- the key used to create the digestdata
- the data use to create teh digestdigest
- the digest to verifyInvalidKeyException
- thrown is the key is not the correct formatCopyright © 2021. All rights reserved.