我试图读取UTF-16编码方案中的字符串并对其执行MD5散列.但奇怪的是,当我尝试这样做时,Java和C#会返回不同的结果.
以下是Java中的一段代码:
public static void main(String[] args) {
String str = "preparar mantecado con coca cola";
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
digest.update(str.getBytes("UTF-16"));
byte[] hash = digest.digest();
String output = "";
for(byte b: hash){
output += Integer.toString( ( b & 0xff ) + 0x100, 16).substring( 1 );
}
System.out.println(output);
} catch (Exception e) {
}
}
Run Code Online (Sandbox Code Playgroud)
输出为:249ece65145dca34ed310445758e5504
以下是C#中的一段代码:
public static string GetMD5Hash()
{
string input = "preparar mantecado con coca cola";
System.Security.Cryptography.MD5CryptoServiceProvider x = new …Run Code Online (Sandbox Code Playgroud)