什么时候应该使用SHA-1,当我应该使用SHA-2? [英] When should I use SHA-1 and when should I use SHA-2?

查看:265
本文介绍了什么时候应该使用SHA-1,当我应该使用SHA-2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的C#应用​​程序,我使用的RSA我公司由是谁上传,在这里我必须选择SHA-1或SHA-2来计算哈希值。这个人在数据库上被上传前签署文件< BR>
作为编程任何其他组件,我知道必须有一个使用此位置和使用,还有两个人。结果
所以,当这个?而当

In my c# application, I'm using RSA to sign files before being uploaded on the database of my company by the person who is uploading and here I have to choose SHA-1 or SHA-2 for computing the hash.
As any other component in programming, I know that there must be a "use this here" and "use that there" for the two of them.
So, When this? and when that?

编辑:?结果
我的问题是:对业绩有什么区别?而不是关于安全,因为我已经知道,SHA-2更坚实的安全比SHA-1。结果
在此的链接不同类型的SHA-2之间的比较,指出时使用SHA-512,当不到底。我需要有关SHA-1和SHA-2类似的说法。


My question is: What is the difference regarding performance? and not regarding security, as I already know that SHA-2 is more solid secure than SHA-1.
In this Link a comparison between different types of SHA-2 noting when to use SHA-512 and when not in the end. I need a similar argument about SHA-1 and SHA-2.

推荐答案

使用SHA-2。总是。 SHA-1,须保留到SHA-2不能因与遗留代码用于互操作性问题的情况。

Use SHA-2. Always. SHA-1 shall be reserved to situations where SHA-2 cannot be used due to interoperability issues with legacy code.

有没有性能问题,直到已执行的实际措施。 Hash函数的速度快。在大多数情况下,散列函数性能仅具有可忽略不计的影响;即使检测它可能证明是困难的。安全性是第一位的。由于弱点在SHA-1被发现,用它仍然需要一些强大的理由。使用SHA-256将不被质疑;这就是默认选择。但是,如果你使用SHA-1,准备好被批评

There is no performance issue until actual measures have been performed. Hash functions are fast. In most situations, hash function performance has only negligible impact; even detecting it could prove difficult. Security comes first. Since weaknesses have been found in SHA-1, using it nonetheless requires some robust justification. Using SHA-256 will not be questioned; this is the "default choice". But if you use SHA-1, prepare to be criticized.

请注意,有的的被称为SHA-2功能:SHA -224,SHA-256,SHA-384和SHA-512。 SHA-224和SHA-256是相同的功能,保存为内部参数(即初始值)和输出大小(SHA-224输出的大小是28字节,而SHA-256提供了32个字节);它们具有相同的性能特性。同样,SHA-384和SHA-512同样的功能性能,明智的。 SHA-512使用64位算术运算,并在其上提供的64位的操作码的平台的速度比的SHA-256;在32位平台上,SHA-256会更快(注:在32位x86原生代码,就可以使用SSE2操作码和64位计算能力,因此的部分的原生SHA-512的代码实现将在32位模式下比SHA-256快; OpenSSL的代码所做的,但是,据我所知,在.NET中的SHA-512实现托管代码)。此外,所有的SHA-*函数有一些基本的粒度,因为它们由组块处理数据:为SHA-256,组块是64字节长,而SHA-512,使用128字节块;散列非常短的数据元素时,较高的SHA-512粒度相应降低其性能。最后,SHA-256(32位平台上)很可能会产生更小的代码(即使用在CPU上较少的L1高速缓存)。

Note that there are four functions known as "SHA-2": SHA-224, SHA-256, SHA-384 and SHA-512. SHA-224 and SHA-256 are the same function, save for an internal parameter (the "initial value") and the output size (SHA-224 output size is 28 bytes, whereas SHA-256 offers 32 bytes); they have the same performance characteristics. Similarly, SHA-384 and SHA-512 are the same function performance-wise. SHA-512 uses 64-bit arithmetic operations and is faster than SHA-256 on platforms which offer 64-bit opcodes; on 32-bit platforms, SHA-256 will be faster (note: on 32-bit x86 with native code, it is possible to use the SSE2 opcodes and their 64-bit computing abilities, hence some native code implementations of SHA-512 will be faster than SHA-256 in 32-bit mode; the OpenSSL code does that; but, as far as I know, the SHA-512 implementation in .NET is "managed code"). Also, all the SHA-* functions have some basic granularity, because they process data by chunks: for SHA-256, chunks are 64-byte long, whereas SHA-512 uses 128-byte chunks; when hashing very short data elements, the higher SHA-512 granularity correspondingly lowers its performance. Finally, SHA-256 (on a 32-bit platform) is likely to yield smaller code (i.e. use less L1 cache on the CPU).

所以,当有疑问使用SHA-256。如果你打算使用SHA-1,那么你应该怀疑。

So, when in doubt, use SHA-256. If you plan on using SHA-1 then you should doubt.

如果你想使用的哈希函数非加密的使用(即弱点是没有问题的你),然后,而不是SHA-1,审议 MD4

If you want to use a hash function for a non-cryptographic usage (i.e. the weaknesses are not a problem for you) then, instead of SHA-1, consider MD4.

这篇关于什么时候应该使用SHA-1,当我应该使用SHA-2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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