乾草有我想要散列Windows Phone的一個字符串的MD5 ......但是當我調用MD5類我得到以下錯誤MD5哈希中的WindowsPhone 8
The type or namespace name 'MD5' could not be found (are you missing a using directive or an assembly reference?)
PS:我已經使用System.Security.Cryptography名稱空間
所以我怎樣才能在Windows Phone中使用MD5哈希? 這裏是我的代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
namespace FluoraPin
{
class HASHING
{
public static string GetMd5Hash(MD5 md5Hash, string input)
{
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}
// t verify md5 hashing
private bool VerifyMd5Hash(MD5 md5Hash, string input, string hash)
{
// Hash the input.
string hashOfInput = GetMd5Hash(md5Hash, input);
// Create a StringComparer an compare the hashes.
StringComparer comparer = StringComparer.OrdinalIgnoreCase;
if (0 == comparer.Compare(hashOfInput, hash))
{
return true;
}
else
{
return false;
}
}
}
}
沒有答案,但:我假設你知道MD5壞了? –
nooop我不知道!謝謝你建議什麼? – a3adel
使用[SHA-256](http://en.wikipedia.org/wiki/SHA-256),可通過['SHA526Managed'類](http://msdn.microsoft .COM/EN-US /庫/ WindowsPhone的/開發/ system.security.cryptography.sha256managed(v = vs.105)的.aspx)。 [另一個SO問題的答案](http://stackoverflow.com/a/1756222/1810429)提供了一個如何在C#中用SHA256Managed進行散列的例子。 – J0e3gan