Java HMAC hmacSha1(String input, byte[] keyBytes)

Here you can find the source of hmacSha1(String input, byte[] keyBytes)

Description

Hmac sha1.

License

Open Source License

Parameter

Parameter Description
input the input
keyBytes the key bytes

Return

the byte[]

Declaration

public static byte[] hmacSha1(String input, byte[] keyBytes) 

Method Source Code


//package com.java2s;
import java.security.GeneralSecurityException;

import javax.crypto.Mac;
import javax.crypto.SecretKey;

import javax.crypto.spec.SecretKeySpec;

public class Main {
    /** The Constant HMACSHA1. */
    private static final String HMACSHA1 = "HmacSHA1";

    /**/*from  w w w. ja v  a2  s.com*/
     * Hmac sha1.
     *
     * @param input the input
     * @param keyBytes the key bytes
     * @return the byte[]
     */
    public static byte[] hmacSha1(String input, byte[] keyBytes) {
        try {
            SecretKey secretKey = new SecretKeySpec(keyBytes, HMACSHA1);
            Mac mac = Mac.getInstance(HMACSHA1);
            mac.init(secretKey);
            return mac.doFinal(input.getBytes());
        } catch (GeneralSecurityException e) {
            throw new IllegalStateException("Security exception", e);
        }
    }
}

Related

  1. hmacSha1(byte[] key_bytes, byte[] text_bytes)
  2. hmacSha1(byte[] secret, byte[] data)
  3. hmacSha1(SecretKey key, byte[] data)
  4. hmacSha1(SecretKeySpec signingKey, byte[]... data)
  5. hmacSha1(String data, String key)
  6. hmacSha1(String input, byte[] keyBytes)
  7. hmacSHA256(byte[] secret, byte[] data)
  8. hmacSha256(String keyHex, String stringData)
  9. hmacsha256Representation(String data, String pusherApplicationSecret)