首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >窗口hashing 8中的MD5散列

窗口hashing 8中的MD5散列
EN

Stack Overflow用户
提问于 2014-02-23 02:09:11
回答 4查看 4.9K关注 0票数 2

我想在windows中散列到MD5的字符串.但是,当我调用MD5类时,会得到以下错误

无法找到类型或命名空间名称'MD5‘(您是缺少使用指令还是程序集引用?)

PS:我使用了System.Security.Cryptography名称空间

那么,如何使用windows中的MD5哈希呢?这是我的密码

代码语言:javascript
复制
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;
            }
        }
    }
}
EN

回答 4

Stack Overflow用户

发布于 2014-02-23 03:07:55

我认为错误的答案是正确的:

无法找到类型或命名空间名称'MD5‘(您是缺少使用指令还是程序集引用?)

MD5不是Windows的System.Security.Cryptography命名空间中的一个类。有关确认,请参见Windows页面

相比之下,页,MD5作为名称空间中的一个类列出。

尽管如此,您确实应该使用沙-256或更高版本,而不是使用MD5或SHA-1散列。

通过SHA256Managed类为Windows 7和8提供了SHA-256散列--在您已经使用的Security.Security.Cryptography命名空间中。有关如何使用SHA256Managed的示例,请参阅对相关问题的回答

票数 2
EN

Stack Overflow用户

发布于 2014-05-18 21:24:02

这个人在C#中有一个C#哈希的实现,可以用于WP8:

http://upadhyayjitesh.blogspot.com/2013/01/windows-phone-md5-hash-conversion.html

票数 2
EN

Stack Overflow用户

发布于 2016-02-16 13:56:38

您可以向您的项目中添加一个NuGet包。它支持MD5哈希(以及更多的加密算法)。有关详细信息,请参阅其NuGet页面。或其项目页面"弹跳城堡的军团

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21963272

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档