java:
public class MD5  {
    public static String hex(byte[] array) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < array.length; ++i) {
            sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).toUpperCase().substring(1,3));
        }
        return sb.toString();
    }    public static String encrypt(String message) { 
        try { 
            MessageDigest md = MessageDigest.getInstance("MD5"); 
            return hex (md.digest(message.getBytes("ISO8859-1"))); 
        } catch (NoSuchAlgorithmException e) { 
        } catch (UnsupportedEncodingException e) { 
        } 
        return null;
    }    public static void main(String[] args) {
        System.out.println (encrypt("Hello, world!"));
    }
}c#
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(cleanString,"MD5").ToLower();
都32位的

解决方案 »

  1.   

    http://www.cjsdn.net/post/view?bid=6&id=8785&sty=1&tpg=8&age=0
      

  2.   

    .Net中系统类库本身提供了MD5等多种散列、 Hash、DES等多种算法使用很方便就MD5而言.Net中直接提供了两种实现方式:1. 引入System.Web.Security命名空间using System.Web.Security;使用String md5Code = FormsAuthentication.HashPasswordForStoringInConfigFile(Session["username"].ToString(),"MD5");就可将Session中的username进行MD5提取使用最为方便,唯一要注意的是md5Code的大小写问题可以用md5Code.ToLower()等类似方法进行转换2. 引入System.Security.Cryptography命名空间using System.Security.Cryptography;使用   MD5 md5  = new MD5CryptoServiceProvider();
       byte[] fromData = System.Text.Encoding.Default.GetBytes(myString);
       byte[] targetData = md5.ComputeHash(fromData);
    这种方式进行md5计算,也可以获得MD5值,但这里要注意,这种方式是非常灵活的,可以针对不同的字符编码进行计算,主要是这句转换
    System.Text.Encoding.Default.GetBytes(myString);注意里面的Default,这里还可以用其它编码方式,如ASCII,UTF7,UTF8,Unicode等方式
    会直接影响MD5最后提取值,试验后发现用Default可以与Java等第三方加密结果一致而FormsAuthentication.HashPasswordForStoringInConfigFile可能也是走的Default所以我在一开始发现FormsAuthentication.HashPasswordForStoringInConfigFile与Java等第
    三方MD5提取值一致,而md5.ComputeHash提取值不同,查找资料后,改为Default后问题解决