C# windowsphone 8中的MD5哈希
嘿,我正在尝试在windows phone中将字符串散列到MD5。。。但是当我调用MD5类时,我得到以下错误 找不到类型或命名空间名称“MD5”(是否缺少 使用指令或组件参考? PS:我使用了System.Security.Cryptography名称空间C# windowsphone 8中的MD5哈希,c#,hash,windows-phone,md5,C#,Hash,Windows Phone,Md5,嘿,我正在尝试在windows phone中将字符串散列到MD5。。。但是当我调用MD5类时,我得到以下错误 找不到类型或命名空间名称“MD5”(是否缺少 使用指令或组件参考? PS:我使用了System.Security.Cryptography名称空间 那么如何在windows phone中使用MD5哈希呢? 这是我的密码 using System; using System.Collections.Generic; using System.Linq; using System.Text;
那么如何在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;
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Security.Cryptography;
氟哌啶
{
类散列
{
公共静态字符串GetMd5Hash(MD5 md5Hash,字符串输入)
{
//将输入字符串转换为字节数组并计算哈希。
byte[]data=md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
//创建新的Stringbuilder以收集字节
//并创建一个字符串。
StringBuilder sBuilder=新StringBuilder();
//循环遍历散列数据的每个字节
//并将每个字符串格式化为十六进制字符串。
for(int i=0;i
我没有测试您的解决方案,但我找到了一个适合我的解决方案
使用System.Security.Cryptography代码>
class MD5Hash
{
public String getHash(String input)
{
MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
sb.Append(hash[i].ToString("x2"));
return sb.ToString();
}
public Boolean VerifyHash(String input, String hash)
{
String hashOfInput = getHash(input);
StringComparer comparer = StringComparer.OrdinalIgnoreCase;
if (0 == comparer.Compare(hashOfInput, hash))
return true;
else
return false;
}
}
类MD5Hash
{
公共字符串getHash(字符串输入)
{
MD5 MD5=System.Security.Cryptography.MD5.Create();
byte[]inputBytes=Encoding.ASCII.GetBytes(输入);
byte[]hash=md5.ComputeHash(inputBytes);
StringBuilder sb=新的StringBuilder();
for(int i=0;i
这将散列您的字符串,完全没有错误
此外,如果您遇到错误,请检查您是否正在编译包含文本“Client Profile”的.Net版本
我是新来的,所以如果我完全弄错了,那么我很抱歉你能更具体地回答你的问题。我认为错误中的答案是正确的:
找不到类型或命名空间名称“MD5”(是否缺少using指令或程序集引用?)
MD5
不是Windows Phone的System.Security.Cryptography
命名空间中的类。请参阅以获得确认
这与将MD5
列为命名空间中的一个类相比
说到这里,您应该真正使用或更高版本,而不是MD5或SHA-1哈希
SHA-256哈希可通过您正在使用的Security.Security.Cryptography
命名空间中的SHA256Managed
类用于Windows Phone 7和8。有关如何使用SHA256Managed
的示例,请参阅。此人在C#中实现了可用于WP8的MD5哈希:
您可以将Bouncy Castle作为NuGet包添加到项目中。它支持MD5哈希(以及更多的加密算法)。有关更多详细信息,请参见其页面。或者它的项目页面“不是答案,但是:我假设你知道MD5坏了?不,我不知道!!谢谢。您有什么建议?使用,可通过Windows Phone 7和8获得。提供了一个示例,说明如何在C#System.Security.Cryptography.MD5中使用SHA256Managed
进行哈希。windows Phone上不提供此选项,但我需要MD5对API查询进行签名。这是一个非常明显的答案。试着解决这个问题怎么样?