java基础---->摘要算法的介绍 (转)
数据摘要算法是密码学算法中非常重要的一个分支,它通过对所有数据提取指纹信息以实现数据签名、数据完整性校验等功能,由于其不可逆性,有时候会被用做敏感信息的加密。数据摘要算法也被称为哈希(Hash)算法、散列算法。今天,我们就开始java中摘要算法的学习。
项目结构如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAR8AAAFWCAIAAADfYg6+AAAgAElEQVR4nO2d6XsTV57v9XfcF/fFfeZy5w6Z6ZtObBxlaQJJSDLpLD2Tbkg6rNPqoZueTIck7BDAGyYEBZuEAGEzizHGrFaMwRizY7wEYwxIXmUH27Jly7Zsl7xQ90VJpVNV51SVVCqpjur3eerplqvOOXVE6qM6KtX5loUFAEAfLInuAAAkLbG0q6/f90P+qdx9hbn7CvcePjXsH0G3dvUPf5x1Koa7AwCDE0u77LuPdf/S7O1p7+tpe/Tg59wf8tGtnb1Ds7/MJ9UFgOQjNnb1eLybsnIfVmweadoeaNo2+iDLc23dD1tWfbE254u1OZuycns83tjZ5bBZrHZXLFoCAD2JjV2bsnKHnpSzg1cxy9TY1MTowMAg2S6X3WqxOeRWCInILpfdapFrDAB0IzZ2rdiQx/ZfxC8sy33dSoxdLrvVapVtTUV/ACAq1NpVUVGRnZ1N2rp87Y+s5wx+eTo1+8v8C9XNmceuL/r6LK62jna57Far3eWwRWQL2AXEBlV2lZeXT58+fdq0aaQCf/38IPvLUW6Z6jhy8dThr9ILPl2e/+ny/MaHv5y95Zy5/NAbK4/cefRL8Zk6SW2yXeiW8GuHzWK1220WDr5gqKTDxr/k5BL5yDXksFksoZWOUFtouxb4cgdoRNkuTq25c+fK2PWJ7QDbvpdt3zvm/HHdpoLc0w/OtE9xy3n3lJd5yhVr7Bn782cnJbVddqtFgrxdIX9cdiuiiNXuEogUfo2u5XbH6+ywiT2CcxcQGxTs4tWaN2+ejF2377YPu8r6aw4EvE1VzoHChwHpsuda358+d3T8MiipHdW5K6wKKpPgjIMXTbQ7zDAT7AJig5xdqF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BwFRuCK5ICKu3igFwNwOBQbBcAGBywCwD0AuwCAL0AuwBAL/4/4CKggCAcaF8AAAAASUVORK5CYII=" alt="" />
SHA算法
安全哈希算法(Secure Hash Algorithm)主要适用于数字签名标准(Digital Signature Standard DSS)里面定义的数字签名算法(Digital Signature Algorithm DSA)。对于长度小于2^64位的消息,SHA1会产生一个160位的消息摘要。该算法经过加密专家多年来的发展和改进已日益完善,并被广泛使用。该算法的思想是接收一段明文,然后以一种不可逆的方式将它转换成一段(通常更小)密文,也可以简单的理解为取一串输入码(称为预映射或信息),并把它们转化为长度较短、位数固定的输出序列即散列值(也称为信息摘要或信息认证代码)的过程。散列函数值可以说是对明文的一种“指纹”或是“摘要”所以对散列值的数字签名就可以视为对此明文的数字签名。
一、 HuhxSHA.java
package com.huhx.md; import java.security.MessageDigest; import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.SHA1Digest;
import org.junit.Test; /**
* wirter: huhx
*/
public class HuhxSHA {
private static String src = "http://www.cnblogs.com/huhx"; // jdk版本的sha算法
@Test
public void jdkSHA1() {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA");
messageDigest.update(src.getBytes());
byte[] shaBytes = messageDigest.digest();
System.out.println("jdk SHA 1: " + Hex.encodeHexString(shaBytes));
} catch (Exception e) {
e.printStackTrace();
}
} // commons-codec的sha算法
@Test
public void bcSHA1() {
Digest digest = new SHA1Digest();
digest.update(src.getBytes(), 0, src.length()); byte[] shaBytes = new byte[digest.getDigestSize()];
digest.doFinal(shaBytes, 0);
System.out.println("bc SHA 1: " + org.bouncycastle.util.encoders.Hex.toHexString(shaBytes));
} // bcprov的sha算法
@Test
public void ccSHA1() {
System.out.println("cc SHA 1: " + DigestUtils.sha1Hex(src.getBytes()));
}
}
二、 运行结果如下:
jdk SHA 1: 14ed5f04b940042df8dfcd5e60dc331dfddac16f
bc SHA 1: 14ed5f04b940042df8dfcd5e60dc331dfddac16f
cc SHA 1: 14ed5f04b940042df8dfcd5e60dc331dfddac16f
MD算法
MD2
Rivest在1989年开发出MD2算法。在这个算法中,首先对信息进行数据补位,使信息的字节长度是16的倍数。然后,以一个16位的检验和追加到信息末尾,并且根据这个新产生的信息计算出散列值。后来,Rogier和Chauvaud发现如果忽略了检验将和MD2产生冲突。MD2算法加密后结果是唯一的(即不同信息加密后的结果不同)。
MD4
为了加强算法的安全性,Rivest在1990年又开发出MD4算法。MD4算法同样需要填补信息以确保信息的比特位长度减去448后能被512整除(信息比特位长度mod 512 = 448)。然后,一个以64位二进制表示的信息的最初长度被添加进来。信息被处理成512位damg?rd/merkle迭代结构的区块,而且每个区块要通过三个不同步骤的处理。Den boer和Bosselaers以及其他人很快的发现了攻击MD4版本中第一步和第三步的漏洞。Dobbertin向大家演示了如何利用一部普通的个人电脑在几分钟内找到MD4完整版本中的冲突(这个冲突实际上是一种漏洞,它将导致对不同的内容进行加密却可能得到相同的加密后结果)。毫无疑问,MD4就此被淘汰掉了。尽管MD4算法在安全上有个这么大的漏洞,但它对在其后才被开发出来的好几种信息安全加密算法的出现却有着不可忽视的引导作用。
MD5
1991年,Rivest开发出技术上更为趋近成熟的md5算法。它在MD4的基础上增加了"安全-带子"(safety-belts)的概念。虽然MD5比MD4复杂度大一些,但却更为安全。这个算法很明显的由四个和MD4设计有少许不同的步骤组成。在MD5算法中,信息-摘要的大小和填充的必要条件与MD4完全相同。Den boer和Bosselaers曾发现MD5算法中的假冲突(pseudo-collisions),但除此之外就没有其他被发现的加密后结果了。
一、 HuhxMD.java
package com.huhx.md; import java.security.MessageDigest;
import java.security.Security; import org.apache.commons.codec.digest.DigestUtils;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.MD5Digest;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test; public class HuhxMD {
private static String src = "http://www.cnblogs.com/huhx"; @Test
public void jdkMD5() {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
byte[] mdBytes = messageDigest.digest(src.getBytes());
System.out.println("md5 decode: " + Hex.toHexString(mdBytes));
} catch (Exception e) {
e.printStackTrace();
}
} @Test
public void jdkMD2() {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD2");
byte[] mdBytes = messageDigest.digest(src.getBytes());
System.out.println("md2 decode: " + Hex.toHexString(mdBytes));
} catch (Exception e) {
e.printStackTrace();
}
} @Test
public void bcmMD4() {
// Digest digest = new MD4Digest();
// digest.update(src.getBytes(), 0, src.length());
// byte[] mdBytes = new byte[digest.getDigestSize()];
// digest.doFinal(mdBytes, 0);
// System.out.println("md4 decode: " + Hex.toHexString(mdBytes)); Security.addProvider(new BouncyCastleProvider());
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD4");
byte[] mdBytes = messageDigest.digest(src.getBytes());
System.out.println("md4 decode: " + Hex.toHexString(mdBytes));
} catch (Exception e) {
e.printStackTrace();
}
} //
@Test
public void bcmMD5() {
Digest digest = new MD5Digest();
digest.update(src.getBytes(), 0, src.length());
byte[] mdBytes = new byte[digest.getDigestSize()];
digest.doFinal(mdBytes, 0);
System.out.println("md5 decode: " + Hex.toHexString(mdBytes));
} //
@Test
public void ccMD5() {
String md5String = DigestUtils.md5Hex(src.getBytes());
System.out.println("common md5: " + md5String);
}
}
二、 运行结果如下:
md4 decode: b402321e9a067da3df0c36c8315f8e38
md5 decode: f121bf5f7491466ae75e056f686c4462
md2 decode: 42b6b066b1273470f9aad644cede7644
md5 decode: f121bf5f7491466ae75e056f686c4462
common md5: f121bf5f7491466ae75e056f686c4462
MAC算法
MAC算法 (Message Authentication Codes) 带秘密密钥的Hash函数:消息的散列值由只有通信双方知道的秘密密钥K来控制。此时Hash值称作MAC。
MAC算法原理(以直联银联pos和POS中心通讯为例)。
- 将欲发送给POS中心的消息中,从消息类型(MTI)到63域之间的部分构成MAC ELEMEMENT BLOCK (MAB)。
- 对MAB,按每8个字节做异或(不管信息中的字符格式),如果最后不满8个字节,则添加“0X00”。
一、 HuhxMAC.java
package com.huhx.md; import javax.crypto.KeyGenerator;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec; import org.bouncycastle.crypto.digests.MD5Digest;
import org.bouncycastle.crypto.macs.HMac;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test; public class HuhxMAC { private static String src = "http://www.cnblogs.com/huhx";
private static String decodeKey = "bbbbbbbbbb"; @Test
public void jdkHmacMD5() {
try {
// 初始化KeyGenerator
KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacMD5");
// 产生密钥
SecretKey secretKey = keyGenerator.generateKey();
// 获得密钥
// byte[] keyBytes = secretKey.getEncoded();
byte[] keyBytes = org.apache.commons.codec.binary.Hex.decodeHex(decodeKey.toCharArray());
// 还原密钥
SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "HmacMD5");
// 实例化MAC
Mac mac = Mac.getInstance(secretKeySpec.getAlgorithm());
// 初始化Mac
mac.init(secretKeySpec);
// 执行摘要
byte[] result = mac.doFinal(src.getBytes());
System.out.println("jdk mac: " + Hex.toHexString(result));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} @Test
public void bcHmacMD5() {
HMac hMac = new HMac(new MD5Digest());
hMac.init(new KeyParameter(Hex.decode(decodeKey)));
hMac.update(src.getBytes(), 0, src.length()); byte[] hMacBytes = new byte[hMac.getMacSize()];
hMac.doFinal(hMacBytes, 0);
System.out.println("bc mac: " + Hex.toHexString(hMacBytes));
}
}
二、 运行结果如下:
bc mac: 3bf59d550b1e0d6cee15e015870029f9
jdk mac: 3bf59d550b1e0d6cee15e015870029f9
http://www.cnblogs.com/huhx/p/messageDigest.html
java基础---->摘要算法的介绍 (转)的更多相关文章
- java基础---->摘要算法的介绍
数据摘要算法是密码学算法中非常重要的一个分支,它通过对所有数据提取指纹信息以实现数据签名.数据完整性校验等功能,由于其不可逆性,有时候会被用做敏感信息的加密.数据摘要算法也被称为哈希(Hash)算法. ...
- 【java基础】IOC介绍及其简单实现
控制反转(Inversion of Control,英文缩写为IoC)是一个重要的面向对象编程的法则来削减计算机程序的耦合问题,也是轻量级的Spring框架的核心. 控制反转一般分为两种类型,依赖注入 ...
- Java基础之入门介绍
基础知识 1.JVM.JRE和JDK的区别: JVM(Java Virtual Machine):java虚拟机,用于保证java的跨平台的特性. java ...
- java基础内存分配介绍
java内存分配介绍 栈 堆 方法区 本地方法栈 寄存器 方法区:字节码文件加载时进入的内存. 栈内存:方法运行时所进入的内存,变量也在这里. 堆内存:new出来的东西在这块内存中开辟空间并且 ...
- java基础语法详细介绍
一.概述 1.java语言概述 是SUN(Stanford University Network,斯坦福大学网络公司 ) 1995年推出的一门高级编程语言; java之父---James Goslin ...
- java基础集合底层介绍
ArrayList.Vector.HashMap.HashTable.HashSet的默认初始容量.加载因子.扩容增量 这里要讨论这些常用的默认初始容量和扩容的原因是: 当底层实现涉及到扩容时,容器或 ...
- java基础-学java util类库总结
JAVA基础 Util包介绍 学Java基础的工具类库java.util包.在这个包中,Java提供了一些实用的方法和数据结构.本章介绍Java的实用工具类库java.util包.在这个包中,Java ...
- Java基础笔记 – Annotation注解的介绍和使用 自定义注解
Java基础笔记 – Annotation注解的介绍和使用 自定义注解 本文由arthinking发表于5年前 | Java基础 | 评论数 7 | 被围观 25,969 views+ 1.Anno ...
- java基础介绍(转)
很全面的介绍JAVA基础的文档 Java 编程简介,第 1 部分: Java 语言基础 http://www.ibm.com/developerworks/cn/java/j-introtojava1 ...
随机推荐
- [HTML5游戏开发]简单的《找不同汉字版》,来考考你的眼力吧
本次 游戏 开发需要用到lufylegend.js开源游戏引擎,版本我用的是1.5.2(现在最新的版本是1.6.0). 引擎下载的位置: http://lufylegend.googlecode ...
- 一个带动画效果的颜色选择对话框控件AnimatedColorPickerDialog
android4.4的日历中选择日程显示颜色的时候有一个颜色选择对话框非常漂亮,模仿他的界面我实现了一个类似的对话框,而且带有动画效果. 代码的实现可讲的地方不多,主要是采用了和AlertDialog ...
- jQuery 查询 xml
加载xml:(注:这个方法在Chrome是用不了的,Chrome是禁止访问本地的xml文件,在ie11里面用不了,ie11的xmlDom文档没有load方法) function loadXML(fil ...
- Java基础05 实施接口
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在封装与接口中,private关键字封装了对象的内部成员.经过封装,产品隐藏了内部 ...
- 基于visual Studio2013解决C语言竞赛题之1045打印成绩
题目 解决代码及点评 /* 功能:用记录来描述一个学生的成绩情况,内容包括:姓名.学号.数学成绩和PASCAL成绩. 要求对一个小组的10个学生的成绩进行统计处理: 1)计算学生的总 ...
- 配置开源项目 SlidingMenu 的问题
最近想研究一下开源项目 SlidingMenu,单是配置项目就花了好长的时间,断断续续的尝试,终于配置成功了,写下来和大家分享一下经验. Step 1:导入依赖的项目和例子 打开项目 File -&g ...
- Netty源代码学习——ChannelPipeline模型分析
參考Netty API io.netty.channel.ChannelPipeline A list of ChannelHandlers which handles or intercepts i ...
- 在 Visual Studio 2010 中开发和部署 Windows Azure 应用程序
原文 在 Visual Studio 2010 中开发和部署 Windows Azure 应用程序 在 Visual Studio 2010 中开发和部署 Windows Azure 应用程序 Jim ...
- ios-王云鹤 调用ios系统功能---------------打电话、发短信、发邮件
--------------------------------------菜鸟总结,欢迎读者雅正------------------------------------------------- 先 ...
- BootStrap - FileUpload美化样式
效果: 代码: <div class="panel panel-default" style="border: 1px solid #ffd800;"&g ...