Java HMAC hmacSha1(byte[] key_bytes, byte[] text_bytes)

Here you can find the source of hmacSha1(byte[] key_bytes, byte[] text_bytes)

Description

hmac Sha

License

Open Source License

Declaration

public static byte[] hmacSha1(byte[] key_bytes, byte[] text_bytes)
            throws NoSuchAlgorithmException, InvalidKeyException 

Method Source Code

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

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class Main {
    public static byte[] hmacSha1(byte[] key_bytes, byte[] text_bytes)
            throws NoSuchAlgorithmException, InvalidKeyException {
        Mac hmacSha1;// w w w.  j  a v a  2  s  . com

        try {
            hmacSha1 = Mac.getInstance("HmacSHA1");
        } catch (NoSuchAlgorithmException nsae) {
            hmacSha1 = Mac.getInstance("HMAC-SHA-1");
        }

        SecretKeySpec macKey = new SecretKeySpec(key_bytes, "RAW");
        hmacSha1.init(macKey);
        return hmacSha1.doFinal(text_bytes);
    }
}

Related

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