📄 hash+
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312"><head><title>Hash 算法及其应用</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<link rel="icon" href="http://www.xmlasp.net/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="http://www.xmlasp.net/favicon.ico" type="image/x-icon">
<meta name="description" content=".net/xml等编程资料">
<meta name="generator" content="iwms网站管理系统">
<link rel="stylesheet" href="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/style.css" type="text/css">
<script type="text/javascript" src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/head.js"></script>
<script type="text/javascript">
var urlPrefix="";
var imgMaxWidth=700;
</script>
<script src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-574127-1";
urchinTracker();
</script>
<script type="text/javascript" src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/show.js"></script></head><body>
<div class="twidth">
<div id="sitehead">
<div class="l"></div>
<div class="r"></div>
<div class="m">
<table width="100%">
<tbody><tr align="center"><td width="160">
<a href="http://www.iwms.net/"><img src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/logo.gif" border="0"></a>
</td><td>
<iframe src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/code.htm" name="alimamaifrm" id="alimamaifrm" style="width: 468px; height: 60px;" marginheight="0" marginwidth="0" border="0" frameborder="0" height="60" scrolling="no" width="468"></iframe>
</td><td style="line-height: 120%;" width="100">
<a href="#" onclick="javascript:window.external.addFavorite('http://www.iwms.net/','iwms网站管理系统 by asp.net')">加入收藏</a><br>
<a href="http://www.xmlasp.net/sitemap.aspx">网站地图</a><br>
<a href="http://www.xmlasp.net/search.aspx">网站搜索</a><br>
<div><a href="http://www.xmlasp.net/chinese.aspx?big5=0">简</a> <a href="http://www.xmlasp.net/chinese.aspx?big5=1">繁</a> <a href="http://www.xmlasp.net/chinese.aspx">默</a></div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="navbar">
<div class="l"></div>
<div class="r"></div>
<div class="m">
<script type="text/javascript" src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/popmenu.js" charset="gb2312"></script><a href="http://www.xmlasp.net/default.aspx" class="first">首页</a><a href="http://www.xmlasp.net/imgindex.aspx">图片</a><a href="http://www.xmlasp.net/hot.aspx">热点</a><a href="http://www.xmlasp.net/topiclist.aspx">专题</a><a href="http://www.xmlasp.net/c35.aspx" onmouseover="showmenu(event,35,1,false)" onmouseout="delayhidemenu()"><span style="color: red;">iwms网站系统</span></a><a href="http://www.xmlasp.net/c2.aspx" onmouseover="showmenu(event,2,1,false)" onmouseout="delayhidemenu()">技术文章</a><a href="http://www.xmlasp.net/c49.aspx">iwms模板风格</a><a href="http://www.xmlasp.net/c50.aspx" onmouseover="showmenu(event,50,1,false)" onmouseout="delayhidemenu()">网络文摘</a><a href="http://www.xmlasp.net/c3.aspx" onmouseover="showmenu(event,3,1,false)" onmouseout="delayhidemenu()">Flash欣赏</a><a href="http://www.xmlasp.net/c38.aspx">理财金融</a><a href="http://www.xmlasp.net/c59.aspx" onmouseover="showmenu(event,59,1,false)" onmouseout="delayhidemenu()">软件下载</a>
</div>
</div>
<div id="navsub">
<div class="l"></div>
<div class="r"></div>
<div class="m">
<a href="http://www.xmlasp.net/default.aspx">首页</a> → <a href="http://www.xmlasp.net/c2.aspx">技术文章</a> → <a href="http://www.xmlasp.net/c43.aspx">加密解密算法</a>
</div>
</div>
<div class="mframe">
<div class="tl"></div>
<div class="tr"></div>
<div class="tm">
<div class="moreR">
背景:<img src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/rect.gif" style="background: rgb(237, 240, 245) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" onclick="ContentBg('#EDF0F5')" alt="#EDF0F5">
<img src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/rect.gif" style="background: rgb(250, 251, 230) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" onclick="ContentBg('#FAFBE6')" alt="#FAFBE6">
<img src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/rect.gif" style="background: rgb(255, 242, 226) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" onclick="ContentBg('#FFF2E2')" alt="#FFF2E2">
<img src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/rect.gif" style="background: rgb(253, 230, 224) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" onclick="ContentBg('#FDE6E0')" alt="#FDE6E0">
<img src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/rect.gif" style="background: rgb(243, 255, 225) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" onclick="ContentBg('#F3FFE1')" alt="#F3FFE1">
<img src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/rect.gif" style="background: rgb(218, 250, 243) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" onclick="ContentBg('#DAFAF3')" alt="#DAFAF3">
<img src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/rect.gif" style="background: rgb(234, 234, 239) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" onclick="ContentBg('#EAEAEF')" alt="#EAEAEF">
<img src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/rect.gif" style="background: rgb(255, 255, 255) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" onclick="ContentBg('')" alt="默认">
</div>
<span class="tt">阅读新闻</span>
</div>
<div class="wrapper">
<div class="ml"></div>
<div class="mr"></div>
<div class="mm" id="bodyTd">
<div id="printBody" style="">
<br><div align="center"><h1 class="aTitle">Hash 算法及其应用</h1></div>
<table align="center" width="97%">
<tbody><tr>
<td width="120">[日期:2004-07-30]</td>
<td align="center">来源:<a href="http://dev.csdn.net/develop/article/30/30184.shtm" target="_blank">CSDN</a> 作者:</td>
<td align="right" width="200">[字体:<a href="javascript:ContentSize(16)">大</a> <a href="javascript:ContentSize(0)">中</a> <a href="javascript:ContentSize(12)">小</a>]
</td></tr>
</tbody></table>
<center><script type="text/javascript">
<!--
google_ad_client = "pub-8762723865019686";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al_s";
//2007-09-04: 新闻页
google_ad_channel = "2064388623";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "008000";
//--></script><script src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/show_ads.js" type="text/javascript"></script><iframe name="google_ads_frame" src="hash%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95_files/ads.htm" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" height="15" scrolling="no" width="728"></iframe></center>
<div id="content"><p>--------------- <br>什么是 Hash <br>Hash 的重要特性 <br>Hash 函数的实现 <br>主要的 Hash 算法 <br>Hash 算法的安全问题 <br>Hash 算法的应用 <br>结 论 <br>--------------- </p><p><br>Hash,
一般翻译做“散列”,也有直接音译为"哈希"的,就是把任意长度的输入(又叫做预映射,
pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值。这种转换是一种压缩映射,也就是,散列值的空间通常远小于输入的空间,不
同的输入可能会散列成相同的输出,而不可能从散列值来唯一的确定输入值。 </p><p>数学表述为:h = H(M) ,其中H( )--单向散列函数,M--任意长度明文,h--固定长度散列值。 </p><p></p><p>在信息安全领域中应用的Hash算法,还需要满足其他关键特性: </p><p>第
一当然是单向性(one-way),从预映射,能够简单迅速的得到散列值,而在计算上不可能构造一个预映射,使其散列结果等于某个特定的散列值,即构造相
应的M=H-1(h)不可行。这样,散列值就能在统计上唯一的表征输入值,因此,密码学上的 Hash 又被称为"消息摘要(message
digest)",就是要求能方便的将"消息"进行"摘要",但在"摘要"中无法得到比"摘要"本身更多的关于"消息"的信息。 </p><p>第二是
抗冲突性(collision-resistant),即在统计上无法产生2个散列值相同的预映射。给定M,计算上无法找到M',满足H(M)=H
(M') ,此谓弱抗冲突性;计算上也难以寻找一对任意的M和M',使满足H(M)=H(M')
,此谓强抗冲突性。要求"强抗冲突性"主要是为了防范所谓"生日攻击(birthday
attack)",在一个10人的团体中,你能找到和你生日相同的人的概率是2.4%,而在同一团体中,有2人生日相同的概率是11.7%。类似的,当预
映射的空间很大的情况下,算法必须有足够的强度来保证不能轻易找到"相同生日"的人。 </p><p>第三是映射分布均匀性和差分分布均匀性,散列结果
中,为 0 的 bit 和为 1 的 bit ,其总数应该大致相等;输入中一个 bit 的变化,散列结果中将有一半以上的 bit
改变,这又叫做"雪崩效应(avalanche effect)";要实现使散列结果中出现 1bit 的变化,则输入中至少有一半以上的 bit
必须发生变化。其实质是必须使输入中每一个 bit 的信息,尽量均匀的反映到输出的每一个 bit 上去;输出中的每一个
bit,都是输入中尽可能多 bit 的信息一起作用的结果。 </p><p></p><p>Damgard 和 Merkle
定义了所谓“压缩函数(compression function)”,就是将一个固定长度输入,变换成较短的固定长度的输出,这对密码学实践上
Hash
函数的设计产生了很大的影响。Hash函数就是被设计为基于通过特定压缩函数的不断重复“压缩”输入的分组和前一次压缩处理的结果的过程,直到整个消息都
被压缩完毕,最后的输出作为整个消息的散列值。尽管还缺乏严格的证明,但绝大多数业界的研究者都同意,如果压缩函数是安全的,那么以上述形式散列任意长度
的消息也将是安全的。这就是所谓 Damgard/Merkle 结构: </p><p>在下图中,任意长度的消息被分拆成符合压缩函数输入要求的分
组,最后一个分组可能需要在末尾添上特定的填充字节,这些分组将被顺序处理,除了第一个消息分组将与散列初始化值一起作为压缩函数的输入外,当前分组将和
前一个分组的压缩函数输出一起被作为这一次压缩的输入,而其输出又将被作为下一个分组压缩函数输入的一部分,直到最后一个压缩函数的输出,将被作为整个消
息散列的结果。 </p><p></p><p></p><p>MD5 和 SHA1 可以说是目前应用最广泛的Hash算法,而它们都是以 MD4 为基础设计的。 </p><p>1) MD4 <br>MD4(RFC
1320)是 MIT 的 Ronald L. Rivest 在 1990 年设计的,MD 是 Message Digest
的缩写。它适用在32位字长的处理器上用高速软件实现--它是基于 32 位操作数的位操作来实现的。它的安全性不像RSA那样基于数学假设,尽管
Den Boer、Bosselaers 和 Dobbertin 很快就用分析和差分成功的攻击了它3轮变换中的 2
轮,证明了它并不像期望的那样安全,但它的整个算法并没有真正被破解过,Rivest 也很快进行了改进。 </p><p>下面是一些MD4散列结果的例子: </p><p>MD4 ("") = 31d6cfe0d16ae931b73c59d7e0c089c0 <br>MD4 ("a") = bde52cb31de33e46245e05fbdbd6fb24 <br>MD4 ("abc") = a448017aaf21d8525fc10ae87aa6729d <br>MD4 ("message digest") = d9130a8164549fe818874806e1c7014b <br>MD4 ("abcdefghijklmnopqrstuvwxyz") = d79e1c308aa5bbcdeea8ed63df412da9 <br>MD4 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = 043f8582f241db351ce627e153e7f0e4 <br>MD4 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") = e33b4ddc9c38f2199c3e7b164fcc0536 </p><p><br>2) MD5 <br>MD5(RFC 1321)是 Rivest 于1991年对MD4的改进版本。它对输入仍以512位分组,其输出是4个32位字的级联,与 MD4 相同。它较MD4所做的改进是: </p><p>1) 加入了第四轮 <br>2) 每一步都有唯一的加法常数; <br>3) 第二轮中的G函数从((X ∧ Y) ∨ (X ∧ Z) ∨ (Y ∧ Z)) 变为 ((X ∧ Z) ∨ (Y ∧ ~Z))以减小其对称性; <br>4) 每一步都加入了前一步的结果,以加快"雪崩效应"; <br>5) 改变了第2轮和第3轮中访问输入子分组的顺序,减小了形式的相似程度; <br>6) 近似优化了每轮的循环左移位移量,以期加快"雪崩效应",各轮的循环左移都不同。 <br>尽管MD5比MD4来得复杂,并且速度较之要慢一点,但更安全,在抗分析和抗差分方面表现更好。 </p><p>消
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -