1 package com.test; 2 3 import javax.crypto.Mac; 4 import javax.crypto.spec.SecretKeySpec; 5 import org.apache.commons.codec.binary.Base64; 6 7 8 public class HmacSha1Test { 9 private static final String APP_SECRET = "your_key"; 10 public static void main(String[] args) throws Exception { 11 SecretKeySpec keySpec = new SecretKeySpec( 12 APP_SECRET.getBytes("UTF-8"), 13 "HmacSHA1"); 14 Mac mac = Mac.getInstance("HmacSHA1"); 15 mac.init(keySpec); 16 byte[] result = mac.doFinal("123456".getBytes()); 17 String resultStr = Base64.encodeBase64String(result); 18 } 19 }