c# md5加密翻译成java语言
public static string GetMd5(string source)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(source)));
t2 = t2.Replace("-", "");
return t2;
}
哪位大师能帮忙翻译一下上面的C# md5加密代码,改成java的,小弟感激不尽.....
md5?c#?java
------解决方案--------------------import java.security.MessageDigest;
public static String md5(String source) {
StringBuffer sb = new StringBuffer(32);
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] array = md.digest(source.getBytes("utf-8"));
for (int i = 0; i < array.length; i++) {
sb.append(Integer.toHexString((array[i] & 0xFF)
------解决方案-------------------- 0x100).toUpperCase().substring(1, 3));
}
} catch (Exception e) {
logger.error("Can not encode the string '" + source + "' to MD5!", e);
return null;
}
return sb.toString();
}