美文网首页
在Android中生成HMAC-SHA1 签名

在Android中生成HMAC-SHA1 签名

作者: Aspirinrin | 来源:发表于2014-10-07 16:40 被阅读2342次

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( )

hmacSha1加密函数截图 



相关文章

网友评论

      本文标题:在Android中生成HMAC-SHA1 签名

      本文链接:https://www.haomeiwen.com/subject/ditptttx.html