转载只为自己查阅

转载 2016年08月29日 10:47:27
 

MessageDigest简介

 43315人阅读 评论(5) 收藏 举报
 分类:

本文博客原文

参考文章:http://blog.sina.com.cn/s/blog_4f36423201000c1e.html
一、概述
java.security.MessageDigest类用于为应用程序提供信息摘要算法的功能,如 MD5 或 SHA 算法。简单点说就是用于生成散列码信息摘要是安全的单向哈希函数,它接收任意大小的数据,输出固定长度的哈希值。关于信息摘要散列码请参照《数字证书简介

MessageDigest 通过其getInstance系列静态函数来进行实例化和初始化。MessageDigest 对象通过使用 update 方法处理数据。任何时候都可以调用 reset 方法重置摘要。一旦所有需要更新的数据都已经被更新了,应该调用 digest 方法之一完成哈希计算并返回结果。

对于给定数量的更新数据,digest 方法只能被调用一次。digest 方法被调用后,MessageDigest  对象被重新设置成其初始状态。

MessageDigest 的实现可随意选择是否实现 Cloneable 接口。客户端应用程可以通过尝试复制和捕获 CloneNotSupportedException 测试可复制性:

<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pln"> md </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getInstance</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"SHA"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">try</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">     md</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">update</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">toChapter1</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">     </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pln"> tc1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> md</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">clone</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">     </span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pun" style="color: rgb(102, 102, 0);">[]</span><span class="pln"> toChapter1Digest </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> tc1</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">digest</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">     md</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">update</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">toChapter2</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">     </span><span class="pun" style="color: rgb(102, 102, 0);">...</span><span class="pln">etc</span><span class="pun" style="color: rgb(102, 102, 0);">.</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">catch</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">CloneNotSupportedException</span><span class="pln"> cnse</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">     </span><span class="kwd" style="color: rgb(0, 0, 136);">throw</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">DigestException</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"couldn't make digest of partial content"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></p>

注意1:即时给定MessageDigest的实现是不可复制的,则仍然能够通过getInstance方法实例化几个实例计算来同时进行摘要信息的计算。

注意2:由于历史原因,此类是抽象的,是从 MessageDigestSpi 扩展的。应用程序开发人员只应该注意在此 MessageDigest 类中定义的方法;超类中的所有方法是供希望提供自己的信息摘要算法实现的加密服务提供者使用的。 

注意3MessageDigest并不是单实例的。如下代码所示:

<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln"> </span><span class="pln">        </span><span class="kwd" style="color: rgb(0, 0, 136);">try</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">            </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">                </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pln"> mdTemp1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getInstance</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"MD5"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">                </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pln"> mdTemp2</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getInstance</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"MD5"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">                </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pln"> mdTemp3</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getInstance</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"MD5"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">                </span><span class="typ" style="color: rgb(102, 0, 102);">System</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">out</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">println</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"mdTemp1==mdTemp2?:"</span><span class="pun" style="color: rgb(102, 102, 0);">+(</span><span class="pln">mdTemp1</span><span class="pun" style="color: rgb(102, 102, 0);">==</span><span class="pln">mdTemp2</span><span class="pun" style="color: rgb(102, 102, 0);">));</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">                </span><span class="typ" style="color: rgb(102, 0, 102);">System</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">out</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">println</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"mdTemp2==mdTemp3?:"</span><span class="pun" style="color: rgb(102, 102, 0);">+(</span><span class="pln">mdTemp2</span><span class="pun" style="color: rgb(102, 102, 0);">==</span><span class="pln">mdTemp3</span><span class="pun" style="color: rgb(102, 102, 0);">));</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">            </span><span class="pun" style="color: rgb(102, 102, 0);">}</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">catch</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">NoSuchAlgorithmException</span><span class="pln"> e</span><span class="pun" style="color: rgb(102, 102, 0);">)</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">            </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">                </span><span class="com" style="color: rgb(136, 0, 0);">// TODO Auto-generated catch block</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="com" style="color: rgb(136, 0, 0);">                e.printStackTrace();</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="com" style="color: rgb(136, 0, 0);">            }</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>

运行结果

<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">mdTemp1</span><span class="pun" style="color: rgb(102, 102, 0);">==</span><span class="pln">mdTemp2</span><span class="pun" style="color: rgb(102, 102, 0);">?:</span><span class="pln">false</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">mdTemp2</span><span class="pun" style="color: rgb(102, 102, 0);">==</span><span class="pln">mdTemp3</span><span class="pun" style="color: rgb(102, 102, 0);">?:</span><span class="kwd" style="color: rgb(0, 0, 136);">false</span></p><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
构造方法摘要
protected MessageDigest(String algorithm) 
          创建具有指定算法名称的MessageDigest 实例对象
 
方法摘要
 Object clone() 
          如果实现是可复制的,则返回一个副本。
 byte[] digest() 
          通过执行诸如填充之类的最终操作完成哈希计算。
 byte[] digest(byte[] input) 
          使用指定的字节数组对摘要进行最后更新,然后完成摘要计算。
 int digest(byte[] buf, int offset, int len) 
          通过执行诸如填充之类的最终操作完成哈希计算。
 String getAlgorithm() 
          返回标识算法的独立于实现细节的字符串。
 int getDigestLength() 
          返回以字节为单位的摘要长度,如果提供程序不支持此操作并且实现是不可复制的,则返回 0。
static MessageDigest getInstance(String algorithm) 
          生成实现指定摘要算法的 MessageDigest 对象。
static MessageDigest getInstance(String algorithm, Provider provider) 
          生成实现指定提供程序提供的指定算法的 MessageDigest 对象,如果该算法可从指定的提供程序得到的话。
static MessageDigest getInstance(String algorithm, String provider) 
          生成实现指定提供程序提供的指定算法的 MessageDigest 对象,如果该算法可从指定的提供程序得到的话。
 Provider getProvider() 
          返回此信息摘要对象的提供程序。
static boolean isEqual(byte[] digesta, byte[] digestb) 
          比较两个摘要的相等性。
 void reset() 
          重置摘要以供再次使用。
 String toString() 
          返回此信息摘要对象的字符串表示形式。
 void update(byte input) 
          使用指定的字节更新摘要。
 void update(byte[] input) 
          使用指定的字节数组更新摘要。
 void update(byte[] input, int offset, int len) 
          使用指定的字节数组,从指定的偏移量开始更新摘要。
 void update(ByteBuffer input) 
          使用指定的 ByteBuffer 更新摘要。
二、实际实践
2.1、创建 MessageDigest 对象
计算信息摘(即散列码)要做的第一步是创建 MessageDigest对象 实例。像所有的引擎类一样,获取某类报文摘要算法(即散列算法,比如MD5)的  MessageDigest 对象的途径是调用 MessageDigest 类中的 getInstance 静态 factory 方法:
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">static</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pln"> getInstance</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> algorithm</span><span class="pun" style="color: rgb(102, 102, 0);">)</span></p>
注意:算法名不区分大小写。例如,以下所有调用都是相等的:
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getInstance</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"SHA"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getInstance</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"sha"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getInstance</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"sHa"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
调用程序可选择指定提供者名称,以保证所要求的算法是由已命名提供者实现的:
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">static</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pln"> getInstance</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> algorithm</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> provider</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></p>
调用 getInstance 将返回已初始化过的MessageDigest对象。因此,它不需要进一步的初始化。
2.2、向MessageDigest传送要计算的数据
计算数据的摘要的第二步是向已初始化的MessageDigest对象提供传送要计算的数据。这将通过一次或多次调用以下某个 update(更新)方法来完成:
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> update</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pln"> input</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> update</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pun" style="color: rgb(102, 102, 0);">[]</span><span class="pln"> input</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> update</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pun" style="color: rgb(102, 102, 0);">[]</span><span class="pln"> input</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> offset</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> len</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
2.3、计算摘要
通过调用 update 方法向MessageDigest对象传送要计算的数据后,你就可以调用以下某个 digest(摘要)方法来计算摘要(即生成散列码):
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pun" style="color: rgb(102, 102, 0);">[]</span><span class="pln"> digest</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pun" style="color: rgb(102, 102, 0);">[]</span><span class="pln"> digest</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pun" style="color: rgb(102, 102, 0);">[]</span><span class="pln"> input</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> digest</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pun" style="color: rgb(102, 102, 0);">[]</span><span class="pln"> buf</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> offset</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> len</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
前两个方法返回计算出的摘要。后一个方法把计算出的摘要储存在所提供的 buf 缓冲区中,起点是 offset。len 是 buf 中分配给该摘要的字节数。该方法返回实际存储在 buf 中的字节数。
对第二个接受输入字节数组变量的 digest 方法的调用等价于用指定的输入调用:
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> update</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pun" style="color: rgb(102, 102, 0);">[]</span><span class="pln"> input</span><span class="pun" style="color: rgb(102, 102, 0);">)</span></p>
,接着调用不带参数的 digest 方法.
三、例子演示
3.1、★ 编程思路:
java.security包中的MessageDigest类提供了计算消息摘要即生成散列码的方法,首先生成对象,执行其update( )方法可
以将原始数据传递给该对象,然后执行其digest( )方法即可得到消息摘要。具体步骤如下:
(1)生成MessageDigest对象
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pln"> m</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getInstance</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"MD5"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></p>
MessageDigest类也是一个工厂类,其构造器是受保护的,不允许
直接使用new MessageDigist( )来创建对象,而必须通过其静态方法getInstance( )生成MessageDigest对象
其中传入的参数指定计算消息摘要所使用的算法,常用的有"MD5","SHA"等。
(2)传入需要计算的字符串
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="pln">m</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">update</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">x</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getBytes</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"UTF8"</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">));</span></p>
分析:x为需要计算的字符串,update传入的参数是字节类型或字节类型数组,对于字符串,需要先使用getBytes( )方法生成字符串数组。
(3)计算消息摘要
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pln"> s</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">]=</span><span class="pln">m</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">digest</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">);</span></p>
分析:执行MessageDigest对象的digest( )方法完成计算,计算的结果通过字节类型的数组返回。
(4)处理计算结果
必要的话可以使用如下代码将计算结果(byte数组)转换为字符串。
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">static</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> convertToHexString</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pln"> data</span><span class="pun" style="color: rgb(102, 102, 0);">[])</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">  </span><span class="typ" style="color: rgb(102, 0, 102);">StringBuffer</span><span class="pln"> strBuffer </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">StringBuffer</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln">  </span><span class="kwd" style="color: rgb(0, 0, 136);">for</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> i </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">;</span><span class="pln"> i </span><span class="pun" style="color: rgb(102, 102, 0);"><</span><span class="pln"> data</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">length</span><span class="pun" style="color: rgb(102, 102, 0);">;</span><span class="pln"> i</span><span class="pun" style="color: rgb(102, 102, 0);">++)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">   </span><span class="pln">strBuffer</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">append</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Integer</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">toHexString</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="lit" style="color: rgb(0, 102, 102);">0xff</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">&</span><span class="pln"> data</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">i</span><span class="pun" style="color: rgb(102, 102, 0);">]));</span></div><div><span class="pln">  </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln">  </span><span class="kwd" style="color: rgb(0, 0, 136);">return</span><span class="pln"> strBuffer</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">toString</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
3.2、示例一
完整程序如下:
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">class</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigestDemo</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">extends</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Thread</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> run</span><span class="pun" style="color: rgb(102, 102, 0);">()</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">  </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> text </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="str" style="color: rgb(0, 136, 0);">"abc"</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">  </span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pln"> data</span><span class="pun" style="color: rgb(102, 102, 0);">[]</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">null</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">  </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pln"> m</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">  </span><span class="kwd" style="color: rgb(0, 0, 136);">try</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">   </span><span class="pln">data </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> text</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getBytes</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"UTF8"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">   </span><span class="pln">m </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getInstance</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"MD5"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">   </span><span class="pln">m</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">update</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">data</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">   </span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pln"> resultData</span><span class="pun" style="color: rgb(102, 102, 0);">[]</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> m</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">digest</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln">   </span><span class="typ" style="color: rgb(102, 0, 102);">System</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">out</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">println</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">convertToHexString</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">resultData</span><span class="pun" style="color: rgb(102, 102, 0);">));</span></div><div><span class="pln">  </span><span class="pun" style="color: rgb(102, 102, 0);">}</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">catch</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">NoSuchAlgorithmException</span><span class="pln"> e</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">   </span><span class="com" style="color: rgb(136, 0, 0);">// TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">   </span><span class="com" style="color: rgb(136, 0, 0);">e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">  </span><span class="com" style="color: rgb(136, 0, 0);">} catch (UnsupportedEncodingException e) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">   </span><span class="com" style="color: rgb(136, 0, 0);">// TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">   </span><span class="com" style="color: rgb(136, 0, 0);">e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">  </span><span class="com" style="color: rgb(136, 0, 0);">}</span></div><div>
</div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div>
</div><div><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">static</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> convertToHexString</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">byte</span><span class="pln"> data</span><span class="pun" style="color: rgb(102, 102, 0);">[])</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">  </span><span class="typ" style="color: rgb(102, 0, 102);">StringBuffer</span><span class="pln"> strBuffer </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">StringBuffer</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln">  </span><span class="kwd" style="color: rgb(0, 0, 136);">for</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> i </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">;</span><span class="pln"> i </span><span class="pun" style="color: rgb(102, 102, 0);"><</span><span class="pln"> data</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">length</span><span class="pun" style="color: rgb(102, 102, 0);">;</span><span class="pln"> i</span><span class="pun" style="color: rgb(102, 102, 0);">++)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">   </span><span class="pln">strBuffer</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">append</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Integer</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">toHexString</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="lit" style="color: rgb(0, 102, 102);">0xff</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">&</span><span class="pln"> data</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">i</span><span class="pun" style="color: rgb(102, 102, 0);">]));</span></div><div><span class="pln">  </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln">  </span><span class="kwd" style="color: rgb(0, 0, 136);">return</span><span class="pln"> strBuffer</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">toString</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div class="save_code tracking-ad" data-mod="popu_249" style="position: absolute; height: 60px; right: 30px; top: 5px; color: rgb(255, 255, 255); cursor: pointer; z-index: 2;"><a target=_blank target="_blank" style="color: rgb(12, 137, 207);"><img src="http://static.blog.csdn.net/images/save_snippets.png" style="border: none;" alt="" /></a></div>
★运行结果
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"><span class="lit" style="color: rgb(0, 102, 102);">900150983cd24fb0d6963f7d28e17f72</span></p>
 3.3、示例二
在这里我们将对计算生成的md5使用 sun.misc.BASE64Encoder进行简单的加密。
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> md5sumWithEncoder</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> text</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">throws</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">NoSuchAlgorithmException</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span></div><div><span class="typ" style="color: rgb(102, 0, 102);">UnsupportedEncodingException</span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">        </span><span class="com" style="color: rgb(136, 0, 0);">/*确定计算方法*/</span></div><div><span class="pln">        </span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pln"> md5</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="typ" style="color: rgb(102, 0, 102);">MessageDigest</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getInstance</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"MD5"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">        BASE64Encoder base64en </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln"> BASE64Encoder</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln">        </span><span class="com" style="color: rgb(136, 0, 0);">/*加密后的散列码字符串*/</span></div><div><span class="pln">        </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> strMd5</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">base64en</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">encode</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">md5</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">digest</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">text</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getBytes</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"utf-8"</span><span class="pun" style="color: rgb(102, 102, 0);">)));</span></div><div><span class="pln">        </span><span class="kwd" style="color: rgb(0, 0, 136);">return</span><span class="pln"> strMd5</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
调用函数
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> str</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="str" style="color: rgb(0, 136, 0);">"0123456789"</span></div><div><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">System</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">out</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">println</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span style="line-height: 22px;"><span class="pln" style="line-height: 25px;">md5sumWithEncoder</span></span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">str</span><span class="pun" style="color: rgb(102, 102, 0);">));</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
 输出
eB5eJF1ptWaXm4bijSPyxw==
3.4、示例三
关于此请参考《一点关于计算MD5的封装

25
 
0

我的同类文章

更多文章

参考知识库

img

算法与数据结构知识库

img

Java EE知识库

img

Java SE知识库

img

Java Web知识库

猜你在找
《C语言/C++学习指南》加密解密篇(安全相关算法)
数据结构和算法
数据结构基础系列(1):数据结构和算法
Python算法实战视频课程--队列的应用
Python算法实战视频课程--栈的应用
查看评论
3楼 kellysupeng2016-05-26 18:27发表 [回复]
base64en.encode(md5.digest(text.getBytes("utf-8")))
请问下
md5.digest(text.getBytes("utf-8"))这里本身不应该就是加密过的串么,base64en.encode的用处是什么?
Integer.toHexString()的用处又是什么,转不转换成16进制数据不影响本身的加密吧?
2楼 kellysupeng2016-05-26 18:24发表 [回复]
Integer.toHexString(0xff & data[i])
请问下这里为什么要&0xff
Re: hudashi2016-06-21 15:08发表 [回复]
回复kellysupeng:去负号,转化为int型
1楼 tangyijie12015-04-14 17:02发表 [回复]
convertToHexString方法中的
strBuffer.append(Integer.toHexString(0xff & data[i]));
有问题,当data[i] 是一位数的时候只会返回一个字符。
Re: Mr_ggx2015-12-19 21:06发表 [回复]
回复tangyijie1:你只需要加一个判断即可

String hex=Integer.toHexString(oxff&data[i]);
if(hex.length==1){
strBuffer.append('0');
}
strBuffer.append(hex);
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
     
    1
    • 访问:3667424次
    • 积分:28281
    • 等级: 
    • 排名:第132名
    • 原创:217篇
    • 转载:376篇
    • 译文:178篇
    • 评论:341条
    最新评论
<iframe id="iframeu2734133_0" src="http://pos.baidu.com/acom?sz=250x250&amp;rdid=2734133&amp;dc=2&amp;di=u2734133&amp;dri=0&amp;dis=0&amp;dai=2&amp;ps=3327x87&amp;coa=at%3D3%26rsi0%3D250%26rsi1%3D250%26pat%3D6%26tn%3DbaiduCustNativeAD%26rss1%3D%2523FFFFFF%26conBW%3D1%26adp%3D1%26ptt%3D0%26titFF%3D%2525E5%2525BE%2525AE%2525E8%2525BD%2525AF%2525E9%25259B%252585%2525E9%2525BB%252591%26titFS%3D%26rss2%3D%2523000000%26titSU%3D0%26ptbg%3D90%26piw%3D0%26pih%3D0%26ptp%3D0&amp;dcb=BAIDU_SSP_define&amp;dtm=HTML_POST&amp;dvi=0.0&amp;dci=-1&amp;dpt=none&amp;tsr=0&amp;tpr=1472434222092&amp;ti=MessageDigest%E7%AE%80%E4%BB%8B%20-%20Robin%20Hu%E7%9A%84%E4%B8%93%E6%A0%8F%20-%20%E5%8D%9A%E5%AE%A2%E9%A2%91%E9%81%93%20-%20CSDN.NET&amp;ari=2&amp;dbv=2&amp;drs=3&amp;pcs=1440x805&amp;pss=1440x8745&amp;cfv=0&amp;cpl=5&amp;chi=1&amp;cce=true&amp;cec=UTF-8&amp;tlm=1472434222&amp;rw=805&amp;ltu=http%3A%2F%2Fblog.csdn.net%2Fhudashi%2Farticle%2Fdetails%2F8394158&amp;ltr=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DZaExnhk1Jp-OYFsZ994NQo3KitPy53gRkdNPo2vrFcQF4ZKaoVXV_V-T1cCMfU6l6VlHPlQdi-LzyGZ_l5f21a%26wd%3D%26eqid%3Dfda03971001ed1220000000557c39024&amp;ecd=1&amp;psr=1440x900&amp;par=1436x900&amp;pis=-1x-1&amp;ccd=24&amp;cja=false&amp;cmi=7&amp;col=zh-CN&amp;cdo=-1&amp;tcn=1472434222&amp;qn=77c94dea18067fdf&amp;tt=1472434222071.27.196.262" width="250" height="250" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="border-width: 0px; vertical-align: bottom; margin: 0px;"></iframe>
阅读全文

相关文章推荐

转载只为记录经典之 Nessus scan

Nessus scan  一、Nessus简介 Nessus是一个功能强大而又易于使用的远程安全扫描器,它不仅免费而 且更新极快。安全扫描器的功能是对指定网络进行安全检查,找出该网络是否存在有...

转载只为记录经典之<内核控制路径>

****************************************************************************************************...

转载只为记录经典之<linux write的奥秘>

在Linux下我们在使用设备的时候,都会用到write这个函数,通过这个函数我们可以象使 用文件那样向设备传送数据。可是为什么用户使用write函数就可以把数据写到设备里面 去,这个过程到底是怎么...

转载只为记录经典之<STP 生成树协议>

和其他协议一样,生成树协议也是随着网络的不断发展而不断更新换代的。本文按照技术发展的主线,介绍了生成树协议的发展历程、近期热点和未来的发展方向。   生成树协议是一种二层管理协议,它通过有选择性地阻...

quartz任务调度器的基本原理和使用方法,转载好文章只为大家搜索资源更方便

简介: Quartz 是 OpenSymphony 开源组织在任务调度领域的一个开源项目,完全基于 Java 实现。作为一个优秀的开源调度框架,Quartz 具有功能强大,应用灵活,易于集成的特点。本...

转载只为记录经典之<linux下简单的设备驱动开发 >

linux下简单的设备驱动开发   一.设计原理 Linux内核中的设备驱动程序是一组常驻内存的具有特权的共享库,是低级硬件处理例程。每个文件都有两个设备号,第一个是主设备号,标...

转载只为记录经典之<linux 驱动是什么>

linux 驱动是什么   亚嵌教育—哈里波侠 2010年7月6日      今天给亚嵌29期的就业班的学员上课,提了一个问题“简单说说linux设备驱动是什么?”对于大家的回答都不很令人满意。...

八款开源ANDROID游戏引擎(巨好的资源)[转载,只为收藏而已]

作者: iamsheldon (1 篇文章) 日期: 一月 13, 2012 在 4:30 下午 初学Android游戏开发的朋友,往往会显得有些无所适从,他们常常不知道该从何处入手,每当遇到自己无...
  • slg1988
  • slg1988
  • 2012年05月03日 10:20
  • 397

转载只为记录经典之<va_start va_arg va_end 的使用和原理>

va_start va_arg va_end 的使用和原理   func( Type para1, Type para2, Type para3, ... ) {       /*****...

转载只为记录经典之<Linux下的多线程编程>

Linux下的多线程编程 1 引言   线程(thread)技术早在60年代就被提出,但真正应用多线程到操作系统中去,是在80年代中期,solaris是这方面的佼佼者。传统的Unix也...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:转载只为自己查阅
举报原因:
原因补充:

(最多只允许输入30个字)