/** * Returns a HmacSHA512 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA512 MAC for the given key and value as hex string (lowercase) * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_512, String).hmacHex(String)} */ @Deprecated public static String hmacSha512Hex(final String key, final String valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_512, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA1 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA1 MAC for the given key and value as hex string (lowercase) * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_1, String).hmacHex(String)} */ @Deprecated public static String hmacSha1Hex(final String key, final String valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_1, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA384 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA384 MAC for the given key and value as hex string (lowercase) * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_384, byte[]).hmacHex(byte[])} */ @Deprecated public static String hmacSha384Hex(final byte[] key, final byte[] valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_384, key).hmacHex(valueToDigest); }
/** * Returns a HmacMD5 Message Authentication Code (MAC) as a hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacMD5 MAC for the given key and value as a hex string (lowercase) * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_MD5, String).hmacHex(String)} */ @Deprecated public static String hmacMd5Hex(final String key, final String valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_MD5, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA1 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA1 MAC for the given key and value as hex string (lowercase) * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_1, byte[]).hmacHex(byte[])} */ @Deprecated public static String hmacSha1Hex(final byte[] key, final byte[] valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_1, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA384 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA384 MAC for the given key and value as hex string (lowercase) * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_384, String).hmacHex(String)} */ @Deprecated public static String hmacSha384Hex(final String key, final String valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_384, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA512 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA512 MAC for the given key and value as hex string (lowercase) * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_512, byte[]).hmacHex(byte[])} */ @Deprecated public static String hmacSha512Hex(final byte[] key, final byte[] valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_512, key).hmacHex(valueToDigest); }
/** * Returns a HmacMD5 Message Authentication Code (MAC) as a hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacMD5 MAC for the given key and value as a hex string (lowercase) * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_MD5, byte[]).hmacHex(byte[])} */ @Deprecated public static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_MD5, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA256 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA256 MAC for the given key and value as hex string (lowercase) * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_256, byte[]).hmacHex(byte[])} */ @Deprecated public static String hmacSha256Hex(final byte[] key, final byte[] valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_256, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA256 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA256 MAC for the given key and value as hex string (lowercase) * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_256, String).hmacHex(String)} */ @Deprecated public static String hmacSha256Hex(final String key, final String valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_256, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA1 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA1 MAC for the given key and value as hex string (lowercase) * @throws IOException * If an I/O error occurs. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_1, byte[]).hmacHex(InputStream)} */ @Deprecated public static String hmacSha1Hex(final byte[] key, final InputStream valueToDigest) throws IOException { return new HmacUtils(HmacAlgorithms.HMAC_SHA_1, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA384 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA384 MAC for the given key and value as hex string (lowercase) * @throws IOException * If an I/O error occurs. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_384, byte[]).hmacHex(InputStream)} */ @Deprecated public static String hmacSha384Hex(final byte[] key, final InputStream valueToDigest) throws IOException { return new HmacUtils(HmacAlgorithms.HMAC_SHA_384, key).hmacHex(valueToDigest); }
/** * Returns a HmacMD5 Message Authentication Code (MAC) as a hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacMD5 MAC for the given key and value as a hex string (lowercase) * @throws IOException * If an I/O error occurs. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_MD5, byte[]).hmacHex(InputStream)} */ @Deprecated public static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest) throws IOException { return new HmacUtils(HmacAlgorithms.HMAC_MD5, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA256 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA256 MAC for the given key and value as hex string (lowercase) * @throws IOException * If an I/O error occurs. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_256, byte[]).hmacHex(InputStream)} */ @Deprecated public static String hmacSha256Hex(final byte[] key, final InputStream valueToDigest) throws IOException { return new HmacUtils(HmacAlgorithms.HMAC_SHA_256, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA512 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA512 MAC for the given key and value as hex string (lowercase) * @throws IOException * If an I/O error occurs. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_512, byte[]).hmacHex(InputStream)} */ @Deprecated public static String hmacSha512Hex(final byte[] key, final InputStream valueToDigest) throws IOException { return new HmacUtils(HmacAlgorithms.HMAC_SHA_512, key).hmacHex(valueToDigest); }
@Test public void testMacHexInputStream() throws IOException { Assert.assertEquals(standardResultString, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmacHex(new ByteArrayInputStream(STANDARD_PHRASE_BYTES))); }
@Test public void testMacHexString() throws IOException { Assert.assertEquals(standardResultString, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmacHex(STANDARD_PHRASE_STRING)); }
@Test public void testMacHexByteArray() throws IOException { Assert.assertEquals(standardResultString, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmacHex(STANDARD_PHRASE_BYTES)); }
public AppKeyAuthHandler(Map<String, String> authParams) { params = Maps.newHashMap(); params.putAll(authParams); String appSecret = params.get(PARAM_APP_SECRET); String random = String.valueOf(new Random().nextLong()); String signContent = "random=" + random; String sign = new HmacUtils(HmacAlgorithms.HMAC_SHA_256, appSecret).hmacHex(signContent); params.put(AUTH_TYPE, AUTH_TYPE_APP_KEY); params.put(PARAM_SIGN, sign); params.put(PARAM_RANDOM, random); params.put(PARAM_SIGN_METHOD, SHA_256); params.remove(PARAM_APP_SECRET); }
/** * Returns a HmacSHA512 Message Authentication Code (MAC) as hex string (lowercase) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA512 MAC for the given key and value as hex string (lowercase) * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_512, String).hmacHex(String)} */ @Deprecated public static String hmacSha512Hex(final String key, final String valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_512, key).hmacHex(valueToDigest); }