Class HmacUtils
- java.lang.Object
-
- org.apache.commons.codec.digest.HmacUtils
-
public final class HmacUtils extends java.lang.ObjectSimplifies commonMactasks. This class is immutable and thread-safe.Note: Not all JCE implementations supports all algorithms. If not supported, an IllegalArgumentException is thrown.
- Since:
- 1.10
- Version:
- $Id: HmacUtils.java 1634411 2014-10-27 00:35:43Z ggregory $
-
-
Field Summary
Fields Modifier and Type Field Description private static intSTREAM_BUFFER_LENGTH
-
Constructor Summary
Constructors Constructor Description HmacUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static javax.crypto.MacgetHmacMd5(byte[] key)Returns an initializedMacfor the HmacMD5 algorithm.static javax.crypto.MacgetHmacSha1(byte[] key)Returns an initializedMacfor the HmacSHA1 algorithm.static javax.crypto.MacgetHmacSha256(byte[] key)Returns an initializedMacfor the HmacSHA256 algorithm.static javax.crypto.MacgetHmacSha384(byte[] key)Returns an initializedMacfor the HmacSHA384 algorithm.static javax.crypto.MacgetHmacSha512(byte[] key)Returns an initializedMacfor the HmacSHA512 algorithm.static javax.crypto.MacgetInitializedMac(java.lang.String algorithm, byte[] key)Returns an initializedMacfor the givenalgorithm.static javax.crypto.MacgetInitializedMac(HmacAlgorithms algorithm, byte[] key)Returns an initializedMacfor the givenalgorithm.static byte[]hmacMd5(byte[] key, byte[] valueToDigest)Returns a HmacMD5 Message Authentication Code (MAC) for the given key and value.static byte[]hmacMd5(byte[] key, java.io.InputStream valueToDigest)Returns a HmacMD5 Message Authentication Code (MAC) for the given key and value.static byte[]hmacMd5(java.lang.String key, java.lang.String valueToDigest)Returns a HmacMD5 Message Authentication Code (MAC) for the given key and value.static java.lang.StringhmacMd5Hex(byte[] key, byte[] valueToDigest)Returns a HmacMD5 Message Authentication Code (MAC) as a hex string (lowercase) for the given key and value.static java.lang.StringhmacMd5Hex(byte[] key, java.io.InputStream valueToDigest)Returns a HmacMD5 Message Authentication Code (MAC) as a hex string (lowercase) for the given key and value.static java.lang.StringhmacMd5Hex(java.lang.String key, java.lang.String valueToDigest)Returns a HmacMD5 Message Authentication Code (MAC) as a hex string (lowercase) for the given key and value.static byte[]hmacSha1(byte[] key, byte[] valueToDigest)Returns a HmacSHA1 Message Authentication Code (MAC) for the given key and value.static byte[]hmacSha1(byte[] key, java.io.InputStream valueToDigest)Returns a HmacSHA1 Message Authentication Code (MAC) for the given key and value.static byte[]hmacSha1(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA1 Message Authentication Code (MAC) for the given key and value.static java.lang.StringhmacSha1Hex(byte[] key, byte[] valueToDigest)Returns a HmacSHA1 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.static java.lang.StringhmacSha1Hex(byte[] key, java.io.InputStream valueToDigest)Returns a HmacSHA1 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.static java.lang.StringhmacSha1Hex(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA1 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.static byte[]hmacSha256(byte[] key, byte[] valueToDigest)Returns a HmacSHA256 Message Authentication Code (MAC) for the given key and value.static byte[]hmacSha256(byte[] key, java.io.InputStream valueToDigest)Returns a HmacSHA256 Message Authentication Code (MAC) for the given key and value.static byte[]hmacSha256(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA256 Message Authentication Code (MAC) for the given key and value.static java.lang.StringhmacSha256Hex(byte[] key, byte[] valueToDigest)Returns a HmacSHA256 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.static java.lang.StringhmacSha256Hex(byte[] key, java.io.InputStream valueToDigest)Returns a HmacSHA256 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.static java.lang.StringhmacSha256Hex(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA256 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.static byte[]hmacSha384(byte[] key, byte[] valueToDigest)Returns a HmacSHA384 Message Authentication Code (MAC) for the given key and value.static byte[]hmacSha384(byte[] key, java.io.InputStream valueToDigest)Returns a HmacSHA384 Message Authentication Code (MAC) for the given key and value.static byte[]hmacSha384(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA384 Message Authentication Code (MAC) for the given key and value.static java.lang.StringhmacSha384Hex(byte[] key, byte[] valueToDigest)Returns a HmacSHA384 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.static java.lang.StringhmacSha384Hex(byte[] key, java.io.InputStream valueToDigest)Returns a HmacSHA384 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.static java.lang.StringhmacSha384Hex(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA384 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.static byte[]hmacSha512(byte[] key, byte[] valueToDigest)Returns a HmacSHA512 Message Authentication Code (MAC) for the given key and value.static byte[]hmacSha512(byte[] key, java.io.InputStream valueToDigest)Returns a HmacSHA512 Message Authentication Code (MAC) for the given key and value.static byte[]hmacSha512(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA512 Message Authentication Code (MAC) for the given key and value.static java.lang.StringhmacSha512Hex(byte[] key, byte[] valueToDigest)Returns a HmacSHA512 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.static java.lang.StringhmacSha512Hex(byte[] key, java.io.InputStream valueToDigest)Returns a HmacSHA512 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.static java.lang.StringhmacSha512Hex(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA512 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.static javax.crypto.MacupdateHmac(javax.crypto.Mac mac, byte[] valueToDigest)Updates the givenMac.static javax.crypto.MacupdateHmac(javax.crypto.Mac mac, java.io.InputStream valueToDigest)Updates the givenMac.static javax.crypto.MacupdateHmac(javax.crypto.Mac mac, java.lang.String valueToDigest)Updates the givenMac.
-
-
-
Field Detail
-
STREAM_BUFFER_LENGTH
private static final int STREAM_BUFFER_LENGTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
getHmacMd5
public static javax.crypto.Mac getHmacMd5(byte[] key)
Returns an initializedMacfor the HmacMD5 algorithm.Every implementation of the Java platform is required to support this standard Mac algorithm.
- Parameters:
key- They key for the keyed digest (must not be null)- Returns:
- A Mac instance initialized with the given key.
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.- See Also:
Mac.getInstance(String),Mac.init(Key)
-
getHmacSha1
public static javax.crypto.Mac getHmacSha1(byte[] key)
Returns an initializedMacfor the HmacSHA1 algorithm.Every implementation of the Java platform is required to support this standard Mac algorithm.
- Parameters:
key- They key for the keyed digest (must not be null)- Returns:
- A Mac instance initialized with the given key.
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.- See Also:
Mac.getInstance(String),Mac.init(Key)
-
getHmacSha256
public static javax.crypto.Mac getHmacSha256(byte[] key)
Returns an initializedMacfor the HmacSHA256 algorithm.Every implementation of the Java platform is required to support this standard Mac algorithm.
- Parameters:
key- They key for the keyed digest (must not be null)- Returns:
- A Mac instance initialized with the given key.
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.- See Also:
Mac.getInstance(String),Mac.init(Key)
-
getHmacSha384
public static javax.crypto.Mac getHmacSha384(byte[] key)
Returns an initializedMacfor the HmacSHA384 algorithm.Every implementation of the Java platform is not required to support this Mac algorithm.
- Parameters:
key- They key for the keyed digest (must not be null)- Returns:
- A Mac instance initialized with the given key.
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.- See Also:
Mac.getInstance(String),Mac.init(Key)
-
getHmacSha512
public static javax.crypto.Mac getHmacSha512(byte[] key)
Returns an initializedMacfor the HmacSHA512 algorithm.Every implementation of the Java platform is not required to support this Mac algorithm.
- Parameters:
key- They key for the keyed digest (must not be null)- Returns:
- A Mac instance initialized with the given key.
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.- See Also:
Mac.getInstance(String),Mac.init(Key)
-
getInitializedMac
public static javax.crypto.Mac getInitializedMac(HmacAlgorithms algorithm, byte[] key)
Returns an initializedMacfor the givenalgorithm.- Parameters:
algorithm- the name of the algorithm requested. See Appendix A in the Java Cryptography Architecture Reference Guide for information about standard algorithm names.key- They key for the keyed digest (must not be null)- Returns:
- A Mac instance initialized with the given key.
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.- See Also:
Mac.getInstance(String),Mac.init(Key)
-
getInitializedMac
public static javax.crypto.Mac getInitializedMac(java.lang.String algorithm, byte[] key)Returns an initializedMacfor the givenalgorithm.- Parameters:
algorithm- the name of the algorithm requested. See Appendix A in the Java Cryptography Architecture Reference Guide for information about standard algorithm names.key- They key for the keyed digest (must not be null)- Returns:
- A Mac instance initialized with the given key.
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.- See Also:
Mac.getInstance(String),Mac.init(Key)
-
hmacMd5
public static byte[] hmacMd5(byte[] key, byte[] valueToDigest)Returns a HmacMD5 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacMD5 MAC for the given key and value
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacMd5
public static byte[] hmacMd5(byte[] key, java.io.InputStream valueToDigest) throws java.io.IOExceptionReturns a HmacMD5 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digestThe InputStream must not be null and will not be closed
- Returns:
- HmacMD5 MAC for the given key and value
- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacMd5
public static byte[] hmacMd5(java.lang.String key, java.lang.String valueToDigest)Returns a HmacMD5 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacMD5 MAC for the given key and value
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacMd5Hex
public static java.lang.String hmacMd5Hex(byte[] key, byte[] valueToDigest)Returns a HmacMD5 Message Authentication Code (MAC) as a hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacMD5 MAC for the given key and value as a hex string (lowercase)
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacMd5Hex
public static java.lang.String hmacMd5Hex(byte[] key, java.io.InputStream valueToDigest) throws java.io.IOExceptionReturns a HmacMD5 Message Authentication Code (MAC) as a hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digestThe InputStream must not be null and will not be closed
- Returns:
- HmacMD5 MAC for the given key and value as a hex string (lowercase)
- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacMd5Hex
public static java.lang.String hmacMd5Hex(java.lang.String key, java.lang.String valueToDigest)Returns a HmacMD5 Message Authentication Code (MAC) as a hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacMD5 MAC for the given key and value as a hex string (lowercase)
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha1
public static byte[] hmacSha1(byte[] key, byte[] valueToDigest)Returns a HmacSHA1 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA1 MAC for the given key and value
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha1
public static byte[] hmacSha1(byte[] key, java.io.InputStream valueToDigest) throws java.io.IOExceptionReturns a HmacSHA1 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digestThe InputStream must not be null and will not be closed
- Returns:
- HmacSHA1 MAC for the given key and value
- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha1
public static byte[] hmacSha1(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA1 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA1 MAC for the given key and value
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha1Hex
public static java.lang.String hmacSha1Hex(byte[] key, byte[] valueToDigest)Returns a HmacSHA1 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA1 MAC for the given key and value as hex string (lowercase)
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha1Hex
public static java.lang.String hmacSha1Hex(byte[] key, java.io.InputStream valueToDigest) throws java.io.IOExceptionReturns a HmacSHA1 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digestThe InputStream must not be null and will not be closed
- Returns:
- HmacSHA1 MAC for the given key and value as hex string (lowercase)
- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha1Hex
public static java.lang.String hmacSha1Hex(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA1 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA1 MAC for the given key and value as hex string (lowercase)
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha256
public static byte[] hmacSha256(byte[] key, byte[] valueToDigest)Returns a HmacSHA256 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA256 MAC for the given key and value
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha256
public static byte[] hmacSha256(byte[] key, java.io.InputStream valueToDigest) throws java.io.IOExceptionReturns a HmacSHA256 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digestThe InputStream must not be null and will not be closed
- Returns:
- HmacSHA256 MAC for the given key and value
- Throws:
java.io.IOException- If an I/O error occurs. s * @throws IllegalArgumentException when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha256
public static byte[] hmacSha256(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA256 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA256 MAC for the given key and value
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha256Hex
public static java.lang.String hmacSha256Hex(byte[] key, byte[] valueToDigest)Returns a HmacSHA256 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA256 MAC for the given key and value as hex string (lowercase)
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha256Hex
public static java.lang.String hmacSha256Hex(byte[] key, java.io.InputStream valueToDigest) throws java.io.IOExceptionReturns a HmacSHA256 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digestThe InputStream must not be null and will not be closed
- Returns:
- HmacSHA256 MAC for the given key and value as hex string (lowercase)
- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha256Hex
public static java.lang.String hmacSha256Hex(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA256 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA256 MAC for the given key and value as hex string (lowercase)
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha384
public static byte[] hmacSha384(byte[] key, byte[] valueToDigest)Returns a HmacSHA384 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA384 MAC for the given key and value
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha384
public static byte[] hmacSha384(byte[] key, java.io.InputStream valueToDigest) throws java.io.IOExceptionReturns a HmacSHA384 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digestThe InputStream must not be null and will not be closed
- Returns:
- HmacSHA384 MAC for the given key and value
- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha384
public static byte[] hmacSha384(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA384 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA384 MAC for the given key and value
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha384Hex
public static java.lang.String hmacSha384Hex(byte[] key, byte[] valueToDigest)Returns a HmacSHA384 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA384 MAC for the given key and value as hex string (lowercase)
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha384Hex
public static java.lang.String hmacSha384Hex(byte[] key, java.io.InputStream valueToDigest) throws java.io.IOExceptionReturns a HmacSHA384 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digestThe InputStream must not be null and will not be closed
- Returns:
- HmacSHA384 MAC for the given key and value as hex string (lowercase)
- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha384Hex
public static java.lang.String hmacSha384Hex(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA384 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA384 MAC for the given key and value as hex string (lowercase)
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha512
public static byte[] hmacSha512(byte[] key, byte[] valueToDigest)Returns a HmacSHA512 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA512 MAC for the given key and value
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha512
public static byte[] hmacSha512(byte[] key, java.io.InputStream valueToDigest) throws java.io.IOExceptionReturns a HmacSHA512 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digestThe InputStream must not be null and will not be closed
- Returns:
- HmacSHA512 MAC for the given key and value
- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha512
public static byte[] hmacSha512(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA512 Message Authentication Code (MAC) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA512 MAC for the given key and value
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha512Hex
public static java.lang.String hmacSha512Hex(byte[] key, byte[] valueToDigest)Returns a HmacSHA512 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA512 MAC for the given key and value as hex string (lowercase)
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha512Hex
public static java.lang.String hmacSha512Hex(byte[] key, java.io.InputStream valueToDigest) throws java.io.IOExceptionReturns a HmacSHA512 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digestThe InputStream must not be null and will not be closed
- Returns:
- HmacSHA512 MAC for the given key and value as hex string (lowercase)
- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
hmacSha512Hex
public static java.lang.String hmacSha512Hex(java.lang.String key, java.lang.String valueToDigest)Returns a HmacSHA512 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value.- Parameters:
key- They key for the keyed digest (must not be null)valueToDigest- The value (data) which should to digest (maybe empty or null)- Returns:
- HmacSHA512 MAC for the given key and value as hex string (lowercase)
- Throws:
java.lang.IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught or key is null or key is invalid.
-
updateHmac
public static javax.crypto.Mac updateHmac(javax.crypto.Mac mac, byte[] valueToDigest)Updates the givenMac. This generates a digest for valueToDigest and the key the Mac was initialized- Parameters:
mac- the initializedMacto updatevalueToDigest- the value to update theMacwith (maybe null or empty)- Returns:
- the updated
Mac - Throws:
java.lang.IllegalStateException- if the Mac was not initialized- Since:
- 1.x
-
updateHmac
public static javax.crypto.Mac updateHmac(javax.crypto.Mac mac, java.io.InputStream valueToDigest) throws java.io.IOExceptionUpdates the givenMac. This generates a digest for valueToDigest and the key the Mac was initialized- Parameters:
mac- the initializedMacto updatevalueToDigest- the value to update theMacwithThe InputStream must not be null and will not be closed
- Returns:
- the updated
Mac - Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalStateException- If the Mac was not initialized- Since:
- 1.x
-
updateHmac
public static javax.crypto.Mac updateHmac(javax.crypto.Mac mac, java.lang.String valueToDigest)Updates the givenMac. This generates a digest for valueToDigest and the key the Mac was initialized- Parameters:
mac- the initializedMacto updatevalueToDigest- the value to update theMacwith (maybe null or empty)- Returns:
- the updated
Mac - Throws:
java.lang.IllegalStateException- if the Mac was not initialized- Since:
- 1.x
-
-