介绍
这篇文章给大家分享的是有关Java加密消息摘要算法MAC实现的示例分析的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
MAC是消息摘要算法的第三种实现方式,另外两种方式分别为:MD2 4 \ \ 5,沙。
MAC的jdk实现:1,默认密钥方式
private static void MAC_JDK () { try {才能 ,,KeyGenerator KeyGenerator =, KeyGenerator.getInstance (“HmacMD5");//初始化KeyGenerator ,,SecretKey SecretKey =, keyGenerator.generateKey();//产生密钥 ,,byte [], key =, secretKey.getEncoded();//获得默认密钥 ,, ,,SecretKey restorSecretKey =, new SecretKeySpec(键,“HmacMD5");//还原密钥 ,,Mac Mac =, Mac.getInstance (restorSecretKey.getAlgorithm());//示例化 ,,mac.init (restorSecretKey);//初始化 ,,byte [], hmacMD5Bytes =, mac.doFinal (src.getBytes());//执行摘要 ,,System.out.println (“hmacMD5Byte :“+ Hex.encodeHexString (hmacMD5Bytes)); ,,},catch (Exception e), { ,,e.printStackTrace (); ,,}, 以前,}>2,动态密钥方式:
private static void MAC_JDK_dongtai () { try {才能 ,,byte [], key =, Hex.decodeHex (new char[]{& # 39;一个# 39;& # 39;一个# 39;,& # 39;一个# 39;,& # 39;一个# 39;,& # 39;一个# 39;,& # 39;一个# 39;,& # 39;一个# 39;,& # 39;一个# 39;,& # 39;一个# 39;,& # 39;一个# 39;});//动态获得密钥 ,, ,,SecretKey restorSecretKey =, new SecretKeySpec(键,“HmacMD5");//还原密钥 ,,Mac Mac =, Mac.getInstance (restorSecretKey.getAlgorithm());//示例化 ,,mac.init (restorSecretKey);//初始化 ,,byte [], hmacMD5Bytes =, mac.doFinal (src.getBytes());//执行摘要 ,,System.out.println (“hmacMD5Byte :“+ Hex.encodeHexString (hmacMD5Bytes)); ,,},catch (Exception e), { ,,e.printStackTrace (); ,,}, 以前,}>MAC的BC实现:
private static void MAC_BC () { HMac 才能;HMac =, new HMac (new MD5Digest ()); hmac.init才能(new KeyParameter (org.bouncycastle.util.encoders.Hex.decode (“aaaaaaaaaa"))); hmac.update才能(src.getBytes (),, 0,, src.getBytes () . length); ,, ,,byte [], mac_BC_Byte =, new 字节(hmac.getMacSize());//执行摘要 hmac.doFinal才能(mac_BC_Byte, 0); System.out.println才能(“mac_BC_Byte :“+ Hex.encodeHexString (mac_BC_Byte)); 以前,}>常用的java框架有哪些
1。SpringMVC, Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级网络框架。2。Shiro, Apache Shiro是Java的一个安全框架。3。Mybatis, Mybatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框架.4.Dubbo,达博是一个分布式服务框架.5.Maven, Maven是个项目管理和构建自动化工具.6.RabbitMQ, RabbitMQ是用Erlang实现的一个高并发高可靠AMQP消息队列服务器1:8)。Ehcache, Ehcache是一个纯Java的进程内缓存框架。
感谢各位的阅读!关于“Java加密消息摘要算法MAC实现的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
Java加密消息摘要算法MAC实现的示例分析