Here you can find the source of hmacSha1(String input, byte[] keyBytes)
Parameter | Description |
---|---|
input | the input |
keyBytes | the key bytes |
public static byte[] hmacSha1(String input, byte[] keyBytes)
//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); } } }