Java HMAC hmacSha1(byte[] data, byte[] key)

Here you can find the source of hmacSha1(byte[] data, byte[] key)

Description

Do HMAC-SHA1.

License

Apache License

Return

byte[] as result.

Declaration

public static byte[] hmacSha1(byte[] data, byte[] key) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.security.GeneralSecurityException;

import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

public class Main {
    /**// w w w  .  ja v  a  2s. com
     * Do HMAC-SHA1.
     *
     * @return byte[] as result.
     */
    public static byte[] hmacSha1(byte[] data, byte[] key) {
        SecretKey skey = new SecretKeySpec(key, "HmacSHA1");
        Mac mac;
        try {
            mac = Mac.getInstance("HmacSHA1");
            mac.init(skey);
        } catch (GeneralSecurityException e) {
            throw new RuntimeException(e);
        }
        mac.update(data);
        return mac.doFinal();
    }
}

Related

  1. hmacDigest(String message, String secretKey, String algorithm)
  2. hmacEncode(String algorithm, String input, String privateKey)
  3. hmacHex(String keyString, String message, String hmac)
  4. hmacSha(byte[] keyBytes, byte[] text)
  5. hmacSha(String crypto, String key, String value)
  6. hmacSha1(byte[] key_bytes, byte[] text_bytes)
  7. hmacSha1(byte[] secret, byte[] data)
  8. hmacSha1(SecretKey key, byte[] data)
  9. hmacSha1(SecretKeySpec signingKey, byte[]... data)