public final class MessageAuthCode
extends java.lang.Object
Constructor and Description |
---|
MessageAuthCode(MACType type)
Creates an instance of MessageAuthCode that will use the specified algorithm and
will generate a key (and an IV if necessary).
|
MessageAuthCode(MACType type,
byte[] cryptoKey)
Creates an instance of MessageAuthCode that will use the specified algorithm and
key which is converted from a byte[] to a SecretKey.
|
MessageAuthCode(MACType type,
byte[] key,
javax.crypto.spec.IvParameterSpec iv)
Creates an instance of MessageAuthCode that will use the specified algorithm with
the specified key and iv.
|
MessageAuthCode(MACType type,
java.nio.ByteBuffer cryptoKey)
Creates an instance of MessageAuthCode that will use the specified algorithm and
key which is converted from a ByteBuffer to a SecretKey.
|
MessageAuthCode(MACType type,
javax.crypto.SecretKey cryptoKey)
Creates an instance of MessageAuthCode that will use the specified algorithm and
key.
|
MessageAuthCode(MACType type,
javax.crypto.SecretKey key,
javax.crypto.spec.IvParameterSpec iv)
Creates an instance of MessageAuthCode that will use the specified algorithm with
the specified key and iv.
|
Modifier and Type | Method and Description |
---|---|
void |
addByte(byte input)
Adds the specified byte to the buffer of bytes to be used for MAC generation
|
void |
addBytes(byte[]... input)
Adds the specified byte arrays to the buffer of bytes to be used for MAC generation
|
void |
addBytes(byte[] input,
int offset,
int len)
Adds the specified portion of the byte[] passed in to the buffer
of bytes to be used for MAC generation
|
void |
addBytes(java.nio.ByteBuffer input)
Adds the remaining bytes from a ByteBuffer to the buffer of bytes
to be used for MAC generation.
|
javax.crypto.spec.IvParameterSpec |
genIV()
Generates a new IV to be used.
|
java.nio.ByteBuffer |
genMac()
Generates the MAC of all the bytes in the buffer added with the
addBytes methods.
|
java.nio.ByteBuffer |
genMac(byte[]... input)
Generates the MAC of only the specified bytes.
|
java.nio.ByteBuffer |
genMac(java.nio.ByteBuffer input)
Generates the MAC of only the specified bytes.
|
javax.crypto.spec.IvParameterSpec |
getIv()
Gets the IV being used.
|
javax.crypto.SecretKey |
getKey()
Gets the key being used
|
void |
setIV(javax.crypto.spec.IvParameterSpec iv)
Changes the current iv to the provided iv.
|
static boolean |
verify(byte[] mac1,
byte[] mac2)
Verifies that the two MAC addresses passed are equivalent.
|
static boolean |
verify(java.nio.ByteBuffer mac1,
java.nio.ByteBuffer mac2)
Verifies that the two MAC addresses passed are equivalent.
|
boolean |
verifyData(byte[] otherMac,
byte[]... data)
Generates the MAC of the byte arrays provided and checks to see if that MAC
is the same as the one passed in.
|
boolean |
verifyData(java.nio.ByteBuffer otherMac,
java.nio.ByteBuffer data)
Generates the MAC of the byte arrays provided and checks to see if that MAC
is the same as the one passed in.
|
public MessageAuthCode(MACType type, javax.crypto.SecretKey cryptoKey) throws java.security.InvalidKeyException
type
- The MAC algorithm to usecryptoKey
- The key to usejava.security.InvalidKeyException
public MessageAuthCode(MACType type, byte[] cryptoKey) throws java.security.InvalidKeyException
type
- The MAC algorithm to usecryptoKey
- The key to usejava.security.InvalidKeyException
public MessageAuthCode(MACType type, java.nio.ByteBuffer cryptoKey) throws java.security.InvalidKeyException
type
- The MAC algorithm to usecryptoKey
- The key to usejava.security.InvalidKeyException
public MessageAuthCode(MACType type) throws java.security.InvalidKeyException
type
- The MAC algorithm tojava.security.InvalidKeyException
public MessageAuthCode(MACType type, javax.crypto.SecretKey key, javax.crypto.spec.IvParameterSpec iv) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
key
- They key to be usediv
- The iv to be usedjava.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
public MessageAuthCode(MACType type, byte[] key, javax.crypto.spec.IvParameterSpec iv) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
key
- They key to be used as a byte[]iv
- The iv to be usedjava.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
public final void addByte(byte input)
input
- The byte to addpublic final void addBytes(byte[]... input)
input
- The byte[]s to addpublic final void addBytes(java.nio.ByteBuffer input)
input
- The ByteBuffer to be addedpublic final void addBytes(byte[] input, int offset, int len)
input
- The byte to addoffset
- What byte to start atlen
- How many bytes after offset to add to bufferpublic final java.nio.ByteBuffer genMac()
public final java.nio.ByteBuffer genMac(byte[]... input)
input
- public final java.nio.ByteBuffer genMac(java.nio.ByteBuffer input)
input
- public static final boolean verify(byte[] mac1, byte[] mac2)
mac1
- First MAC to be verifiedmac2
- Second MAC to be verifiedpublic static final boolean verify(java.nio.ByteBuffer mac1, java.nio.ByteBuffer mac2)
mac1
- First MAC to be verifiedmac2
- Second MAC to be verifiedpublic final boolean verifyData(byte[] otherMac, byte[]... data)
otherMac
- The MAC to checkdata
- The data to check the MAC againstpublic final boolean verifyData(java.nio.ByteBuffer otherMac, java.nio.ByteBuffer data)
otherMac
- The MAC to checkdata
- The data to check the MAC againstpublic final javax.crypto.SecretKey getKey()
public final javax.crypto.spec.IvParameterSpec getIv()
public final void setIV(javax.crypto.spec.IvParameterSpec iv) throws java.security.InvalidAlgorithmParameterException
iv
- The new iv to use as IvParameterSpecjava.security.InvalidAlgorithmParameterException
public final javax.crypto.spec.IvParameterSpec genIV()