cri*_*ris 1 c# hash android md5
我同时在android和c#中进行md-5哈希处理.但是对于相同的输入,结果应该是相同的.它在两种语言中的表现方式有什么不同吗?
在这两种情况下我得到不同的输出.以下是md-5计算的c#代码:
//this method hashes the values sent to it using MD5
public static String hashwithmd5(String toHashMD5)
{
byte[] keyArray;
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(toHashMD5));
hashmd5.Clear();
return Convert.ToBase64String(keyArray, 0, keyArray.Length);
}
Run Code Online (Sandbox Code Playgroud)
这里是使用bouncycastle的android中md5的代码
public byte[] Hashing(String toHash) throws Exception{
byte[] hashBytes = toHash.getBytes("UTF-8");
EditText et = (EditText) findViewById(R.id.entry);
org.bouncycastle.crypto.digests.MD5Digest digest = new org.bouncycastle.crypto.digests.MD5Digest();
digest.reset();
digest.update(hashBytes, 0, hashBytes.length);
int length = digest.getDigestSize();
byte[] md5 = new byte[length];
digest.doFinal(md5, 0);
et.setText(md5.toString());
return md5;
}
Run Code Online (Sandbox Code Playgroud)
c#中md5的结果是:XUFAKrxLKna5cZ2REBfFkg ==
android中md5的结果是:[B @ 4053cf40