首页 > 编程语言 > 详细

HMAC算法加密

时间:2017-12-13 18:47:26      阅读:309      评论:0      收藏:0      [点我收藏+]
 1 /**
 2      * HMAC算法加密
 3      * @param message 待加密信息
 4      * @param key 密钥
 5      * @return 
 6      */
 7     public static String HmacSHA256(byte[] message, byte[] key){
 8         long begin = System.currentTimeMillis();
 9         try {
10             Mac hmacSha256Mac = Mac.getInstance("HMACSha256");
11             SecretKeySpec secretKey = new SecretKeySpec(key, "HMACSha256");
12             hmacSha256Mac.init(secretKey);
13             byte[] result = hmacSha256Mac.doFinal(message);
14             long end = System.currentTimeMillis();
15             return Base64.encodeBase64String(result);
16         } catch (Exception e) {
17             e.printStackTrace();
18             return "";
19         }
20     }

 

HMAC算法加密

原文:http://www.cnblogs.com/redhat0019/p/8034036.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!