如何使用SHA1或MD5在C#中?(其中一个是在性能和​​安全性进行验证更好) [英] How to Use SHA1 or MD5 in C#?(Which One is Better in Performance and Security for Authentication)

查看:193
本文介绍了如何使用SHA1或MD5在C#中?(其中一个是在性能和​​安全性进行验证更好)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中我们如何能够自动使用SHA1?
是SHA1比MD5更好?(我们使用散列的用户名和密码,需要速度认证)

In C# how we can use SHA1 automatically?
Is SHA1 better than MD5?(We use hashing for user name and password and need speed for authentication)

推荐答案

不知道你所说的自动的意思,但你应该使用 SHA256 高。同样的总是 使用的盐(的$c$c )与你的哈希值。一个侧面说明,之后,时间已经过去了,采用硬化哈希值远远比使用普通的速度为基础的哈希函数更好。即:散列经过几百次的迭代,或者使用已经证明散列函数,如 bcrypt (这是下面提到我相信)。在.NET中使用SHA256散列函数code示例如下:

Not sure what you mean by automatically, but you should really use SHA256 and higher. Also always use a Salt (code) with your hashes. A side note, after time has passed, using hardened hashes is far better than using a plain speed-based hashing function. I.e.: hashing over a few hundred iterations, or using already proven hashing functions such as bcrypt (which is mentioned below I believe). A code sample for using a SHA256 hash function in .NET is as follows:

byte[] data = new byte[DATA_SIZE];
byte[] result;

using(SHA256 shaM = new SHA256Managed()) {
    result = shaM.ComputeHash(data);
}

将使用SHA256做的伎俩,为您和发现的<一个href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha256%28VS.71%29.aspx">MSDN.

旁注上的SHA1的咔:将SHA-1的裂化以透视

Sidenote on the "cracking" of SHA1: Putting the cracking of SHA-1 in perspective

这篇关于如何使用SHA1或MD5在C#中?(其中一个是在性能和​​安全性进行验证更好)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆