日期:2014-05-18  浏览次数:20617 次

共享原码,将自己用到的一些通用程序都贴出来,比如字符串处理,数据库连接等等.我先来两个.
md5加密的

import   java.math.BigInteger;
import   java.security.MessageDigest;
import   java.security.NoSuchAlgorithmException;

public   class   MD5   {
public   static   String   getMd5(String   str)   {
//   //////////////////////////////////////////////////
//   String
MessageDigest   md;
//   System.out.println(MD5.MD5Encode( "11 "));
//   生成一个MD5加密计算摘要
try   {
md   =   MessageDigest.getInstance( "MD5 ");

//   计算md5函数
md.update(str.getBytes());
//   digest()最后确定返回md5   hash值,返回值为8为字符串。因为md5   hash值是16位的hex值,实际上就是8位的字符
//   BigInteger函数则将8位的字符串转换成16位hex值,用字符串来表示;得到字符串形式的hash值
String   pwd   =   new   BigInteger(1,   md.digest()).toString(16);
//System.out.println(pwd);

//   hex_hmac_md5
/*
  *   if   ( " ".equals(pwd))   {   return   true;   }   else   {   return   false;   }
  */
return   pwd;
}   catch   (NoSuchAlgorithmException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
return   null;
}

//   ////////////////////////////////////////
}
}


------解决方案--------------------
楼主精神可佳!支持中...