java code:
public static String md5Digest(String text) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(text.getBytes());
byte[] b = md.digest();
String result = "";
String temp = "";
for (int i = 0; i < 16; i++) {
temp = Integer.toHexString(b[i] & 0xFF);
if (temp.length() == 1)
temp = "0" + temp;
result += temp;
}
result = result.toLowerCase();
return result;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
csharp code:
public string md5(string text)
{
byte[] ByteData = Encoding.ASCII.GetBytes(text);
//MD5 creating MD5 object.
MD5 oMd5 = MD5.Create();
//Hash değerini hesaplayalım.
byte[] HashData = oMd5.ComputeHash(ByteData);
//convert byte array to hex format
StringBuilder oSb = new StringBuilder();
for (int x = 0; x < HashData.Length; x++)
{
//hexadecimal string value
oSb.Append(HashData[x].ToString("x2"));
}
return oSb.ToString();
}