JAVA 和C# 一致的 MD5 32位加密大写

C# 32位加密大写

public string GetStrMd5(string ConvertString)
        {


            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string t2=BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)));
            t2 = t2.Replace("-", "");
            return t2;
        }

java 32 位加密大写

private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',  
        'A', 'B', 'C', 'D', 'E', 'F' };  
public static String toHexString(byte[] b) {  
    //String to  byte  
    StringBuilder sb = new StringBuilder(b.length * 2);    
    for (int i = 0; i < b.length; i++) {    
        sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);    
        sb.append(HEX_DIGITS[b[i] & 0x0f]);    
    }    
    return sb.toString();    
}  
public String mmd5(String s) {  
    try {  
        // Create MD5 Hash  
        MessageDigest digest = java.security.MessageDigest.getInstance("MD5");  
        digest.update(s.getBytes());  
        byte messageDigest[] = digest.digest();  
                                  
        return toHexString(messageDigest);  
    } catch (NoSuchAlgorithmException e) {  
        e.printStackTrace();  
    }  
                          
    return "";  
}

你可能感兴趣的:(加密,MD5)