自己整理的,发在这里做个备份。 /**/ /**md5.java**Createdon2007年5月14日,下午12:12**Tochangethistemplate,chooseTools|TemplateManager*andopenthetemplateintheeditor.*/ package tools; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /***/ /****@authorzhappy*/ public class md5 ... {/***//**Createsanewinstanceofmd5*/publicmd5()...{}/***//***得到指定文件MD5信息*/publicstaticStringfileMD5(Filefile)...{FileInputStreamfis=null;MessageDigestmd=null;byte[]buf=newbyte[2048];try...{md=MessageDigest.getInstance("MD5");fis=newFileInputStream(file);intnum=fis.read(buf);while(num!=(-1))...{md.update(buf,0,num);num=fis.read(buf);}}catch(FileNotFoundExceptionex)...{ex.printStackTrace();}catch(IOExceptione)...{e.printStackTrace();}catch(NoSuchAlgorithmExceptionex)...{ex.printStackTrace();}returnbytes2Hex(md.digest());}/***//***得到strSrc的文件MD5信息*/publicstaticStringstrMD5(StringstrSrc)...{MessageDigestmd=null;byte[]bt=strSrc.getBytes();StringstrDes=null;try...{md=MessageDigest.getInstance("MD5");md.update(bt);strDes=bytes2Hex(md.digest());//toHexString}catch(NoSuchAlgorithmExceptione)...{e.printStackTrace();}returnstrDes;}/***//***二行制转hex字符串*/publicstaticStringbytes2Hex(byte[]bts)...{Stringdes="";Stringtmp=null;for(inti=0;i<bts.length;i++)...{tmp=(Integer.toHexString(bts[i]&0xFF));if(tmp.length()==1)...{des+="0";}des+=tmp;}returndes;}}