public String MD5(String sInput)
throws Exception{
String algorithm="";
//输入不能为空
if(sInput.trim()==null){
return "null";
}
//指定采用MD5算法
try{
algorithm=System.getProperty("MD5.algorithm","MD5");
}catch(SecurityException se){
}
//定义MessageDigest对象
MessageDigest md=MessageDigest.getInstance(algorithm);
//按照系统缺省的字符编码方式把sInput 转换成字节,并把结果存到一新的字节数组buffer中
byte buffer[]=sInput.getBytes();
//从指定的字节数组buffer的偏移量0开始,用指定的字节数组修改由sInput生成摘要
//count为从 0 开始用的字节数长度。
for(int count=0;count<sInput.length();count++)
{
md.update(buffer,0,count);
}
//通过执行最后的诸如填充的操作完成散列码的计算。 在调用之后复位该摘要
//返回存放结果散列值的字节数组bDigest
byte bDigest[]=md.digest();
//将bDigest转换为大整数bi
BigInteger bi=new BigInteger(bDigest);
//返回bi字符串表示,即最终的编码结果
return(bi.toString(16));
}
![赛德克·巴莱高清迅雷下载[2012最新]](http://apollo.s.dpool.sina.com.cn/nd/dataent/moviepic/pics/156/moviepic_0c35a7d7ffb6999aa26d789512888d1c.jpg)




别跟我说这代码是你写的。
//输入不能为空
if(sInput.trim()==null){
return "null";
}
当然不是了,这是一个MD5的例子。sInput是上文中输入的对象