干草有我想要散列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