SHA1 VS RSA:它们之间有什么区别?
SHA1 和 RSA 有什么区别? 它们只是不同的算法还是它们在某种程度上根本上(即用于不同的事物)不同。
What are the differences between SHA1 and RSA? Are they just different algorithms or are they fundamentally (i.e. used for different things) different on some level.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
根本不同。
SHA1 是一种哈希算法,它是一种单向函数,可将任意大小的输入转换为固定长度的输出(本例中为 160 位)。 加密哈希函数是一种除非通过暴力破解,否则不可能找到给出相同输出的两个输入(例如,使用 128 位函数,您需要平均尝试 2^64 条消息才能找到这样的由于所谓的生日悖论而导致的“碰撞” - 谷歌搜索以获取更多信息)。
事实上,对于 SHA1,情况已不再如此 - 该算法(至少在密码学术语中)现在已被破坏,Xiaoyun Wang 等人描述的碰撞攻击击败了经典的生日攻击。 SHA2 系列并未被破坏,NIST 正在就 SHA3 算法或算法系列达成一致。
编辑 - Google 现已生成并发布了实际的 SHA1 冲突。
RSA 是一种非对称加密算法,将输入加密为可以解密的输出(对比无法逆转的哈希算法)。 它使用不同的密钥进行加密(公共密钥)和解密密钥(私有密钥)。 因此,这可以用于接收来自其他人的加密消息 - 您可以发布您的公钥,但只有拥有私钥的您才能解密用它加密的消息。
如果您反转 RSA 的密钥,它可以用于生成数字签名 - 通过使用您的私钥加密某些内容,任何人都可以使用公钥对其进行解密,并且如果他们确定公钥属于您,那么他们就拥有了确信您是加密原件的人。 这通常与哈希函数结合使用 - 您对输入进行哈希处理,然后使用您的私钥对其进行加密,为您的输入消息提供固定长度的数字签名。
Fundamentally different.
SHA1 is a hash algorithm, which is a one way function, turning an input of any size into a fixed-length output (160 bit in this case). A cryptographic hash function is one for which it should not be possible to find two inputs giving the same output except by brute force (for instance, with a 128-bit function you should need to try on average 2^64 message to find such a "collision" due to something called the birthday paradox - Google it for more).
In fact for SHA1 this is no longer the case - the algorithm is (in cryptographic terms at least) broken now, with a collision attack described by Xiaoyun Wang et al that beats a classic birthday attack. The SHA2 family is not broken, and a process is underway by NIST to agree on a SHA3 algorithm or family of algorithms.
Edit - Google have now generated and published an actual SHA1 collision.
RSA is an asymmetric encryption algorithm, encrypting an input into an output that can then be decrypted (contrast a hash algorithm which can't be reversed). It uses a different key for encryption (the public one) than for decryption (the private one). This can therefore be used to receive encrypted messages from others - you can publish your public key, but only you with the private key can then decrypt the messages that have been encrypted with it.
If you reverse the keys for RSA, it can be used to generate a digital signature - by encrypting something with your private key, anyone can decrypt it with the public key and, if they are sure the public key belongs to you, then they have confidence that you were the one who encrypted the original. This is normally done in conjunction with a hash function - you hash your input, then encrypt that with your private key, giving a digital signature of a fixed length for your input message.
前面的答案已经足够解释了。 但我认为你问这个问题只是因为 SHA 和 RSA 经常一起出现。所以让我解释一下原因。
首先,请记住
RSA 效率不高,但 SHA 有效。
假设您下载了 Windows 7,并且想要确定它是否是 Microsoft 的原始 Windows 7。 如果微软只是用RSA来加密Windows 7,那需要很长的时间,我们根本无法忍受。 因此微软在Windows 7上使用SHA1并生成160位长的数据。 然后微软用 RSA 签署这个 160 位长的数据(使用它的私钥)。
然后,您需要做的就是确保您的公钥来自 Microsoft。 然后也使用SHA1生成160位长的数据。 然后用RSA的公钥解密微软的签名。 然后你只需比较两个 160 位长的数据,看看它们是否匹配。
Answers before are already sufficient explanations. But i think you ask this question just because SHA and RSA often come out together.So let me explain why.
First,keep in mind that
RSA is not efficient, but SHA is.
Suppose you download Windows 7, and want to make sure if it's original Windows 7 from Microsoft. If Microsoft just encrypts Windows 7 by RSA, it will takes a really long time to do that we can't stand it at all. So Microsoft uses SHA1 on Windows 7 and generates a 160 bits long data. And then Microsoft sign this 160 bits long data with RSA (use its private key).
Then, all you need to do is that make sure your public key is from Microsoft. And then use SHA1 to generate a 160 bits long data too. And then use public key of RSA to decrypt the signature of Microsoft. Then you just compare the two 160 bits long data to see if they match.
SHA1 是一种散列算法(文档和证书签名),而 RSA 是一种加密/解密算法(安全通信)。
SHA1 is a hashing algorithm (Document and certification signing) while RSA is an encryption/decryption algorithm (Secure communications).
正如其他人评论的那样,它们本质上是不同的东西,具有不同的功能。 您使用 RSA 将信息打乱为看似随机的形式,同时使用 SHA1 来确保消息的完整性(即没有任何位发生更改)。 在安全应用程序中,您将使用其中之一或两者,具体取决于您需要的功能。
As others have commented, they are fundamentally different things serving different functions. You use RSA to scramble information into a seemingly random form, while you use SHA1 to ensure the integrity of the message (i.e. none of the bits have changed). In a security application, you will use one or both, depending on what functionality you need.
SHA1 是一种加密哈希函数,而 RSA 是一种加密算法。
哈希函数接受一段数据并返回固定长度的字符串。 在加密哈希函数中,所有返回字符串都具有相同的概率。 仅给出哈希值,您无法确定输入,也无法找到给出相同哈希值的另一个输入(概率非常小的情况除外)。 Sha1 存在一些安全缺陷。
加密算法需要一段数据,但输出的长度不是固定的 - 您的加密。 给定输出(加密),您可以(如果您有正确的密钥)确定输入。
SHA1 is a cryptographic hash function, whereas RSA is an algorithm for encryption.
A hash function takes a piece of data and return a string of fixed length. In a cryptographic hash function all return strings have the same probability. Given only the hash number you can't determine the input, nor can you find another input that gives the same hash (excpetion with a very very small probability). Sha1 has some security flaws.
An algorithm for encryption gives takes a piece of data, but the output is not of fixed length - your encryption. Given the output (the encryption) you can (if you have the right keys) determine the input.
SHA 是一种“单向”加密算法。这意味着您无法通过输出(算法结果)到达输入文本。
RSA 是一种“双向”加密解密算法。 这意味着您可以通过输出(加密或编码文本)来获取输入数据(原始文本)。
SHA is a 'one-way' encryption algorithm.It means you can't reach the input text by having output(result of algorithm).
RSA is a 'two-way' encryption decryption algorithm. It means you can reach input data(raw text) by having output (ciphered or encoded text).
安全哈希算法 (SHA) 算法采用长度小于 264 位的消息并生成 160 位消息摘要。 该算法比 MD5 稍慢,但较大的消息摘要使其更能安全地抵御暴力冲突和反转攻击。 安全哈希标准(SHS、FIPS 180)中指定的算法由 NIST 开发。 SHA-1 是 1994 年发布的 SHA 的修订版; 该修订版纠正了 SHA 中未公开的缺陷。 它的设计与 Rivest 开发的 MD4 系列哈希函数非常相似。 ANSI X9.30 标准中也对 SHA-1 进行了描述。
RSA 是一种公钥加密算法。 它是已知的第一个适用于签名和加密的算法,也是公钥密码学领域最早的重大进步之一。 RSA 广泛应用于电子商务协议中,并且在拥有足够长的密钥和使用最新实现的情况下被认为是安全的。
最显着的区别是 SHA 是一种加密算法,而 RSA 既是一种加密算法又是一种签名算法。
2005 年 8 月 16 日,有人宣布可能会发现 SHA 中存在冲突 - 2^63 次运算中的 1 次。 这项研究成果由北京清华大学王晓云教授、Andrew Yao 教授和 Frances Yao 教授共同完成。 它扩展了 Wang、Yin 和 Yu 的工作,证明可以在 2^69 次操作中发现碰撞。 这意味着 SHA 比 RSA 更容易发生冲突 - 但值得注意的是,从未发现两个相似的密钥发生冲突。
The Secure Hash Algorithm (SHA) algorithm takes a message of less than 264 bits in length and produces a 160-bit message digest. The algorithm is slightly slower than MD5, but the larger message digest makes it more secure against brute-force collision and inversion attacks. The algorithm specified in the Secure Hash Standard (SHS, FIPS 180), was developed by NIST. SHA-1 is a revision to SHA that was published in 1994; the revision corrected an unpublished flaw in SHA. Its design is very similar to the MD4 family of hash functions developed by Rivest. SHA-1 is also described in the ANSI X9.30 standard.
RSA is an algorithm for public-key cryptography. It is the first algorithm known to be suitable for signing as well as encryption, and one of the first great advances in public key cryptography. RSA is widely used in electronic commerce protocols, and is believed to be secure given sufficiently long keys and the use of up-to-date implementations.
The most notable difference is that SHA is an encryption algorithm whereas RSA is both an encryption as well as signing algorithm.
On 8/16/2005 it was announced that it is possible to find a collision in SHA-1 in 2^63 operations. This research result is due to Professor Xiaoyun Wang of Tsinghua University in Beijing, together with Professors Andrew Yao and Frances Yao. It extends the work of Wang, Yin, and Yu, which demonstrated that a collision could be found in 2^69 operations. What that means is that it is easier for a collision to occur in SHA than in RSA - but notably, no two similar keys have ever been found that collided.