How to generate HMAC-SHA1 Signature in Android?
base为public key
key为private key
返回String为加密后字符串数据
public static String hmacSha1(String base, String key) throws NoSuchAlgorithmException, InvalidKeyException {
String type = "HmacSHA1";
SecretKeySpec secret = new SecretKeySpec(key.getBytes(), type);
Mac mac = Mac.getInstance(type);
mac.init(secret);
byte[] digest = mac.doFinal(base.getBytes());
return Base64.encodeToString(digest, Base64.DEFAULT);
}//end function hmacSha1( )