如何使用SHA1加密和解密算法? [英] How to use SHA1 Encryption and Decryption algorithm?

查看:1080
本文介绍了如何使用SHA1加密和解密算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用SHA1加密和解密算法?

解决方案

你没有。 SHA不是加密算法,它是哈希算法。区别在于可以反转加密来解密数据并恢复原始输入,哈希算法不能 - 你无法从SHA的输出中获得原始输入。



而不是看DES这样的东西: MSDN [ ^ ] - lkink包含一个基本示例。


SHA1不是加密算法。这是一个哈希算法。加密和散列之间存在非常明显的区别:加密数据可以解密为其原始形式,因为在加密期间没有信息丢失,只是表示不同。哈希不能反转为原始数据,因为在哈希计算期间该信息会丢失(至少应该是这样)。散列的目标是拥有一个非常小的字符串,它只代表原始数据,并且可以与另一个散列进行比较,以确定这些散列的源数据是否相同。



那么 - 你的意图是什么?如果要加密和解密数据,则不能选择SHA1。我建议您使用本网站的搜索功能来查找有关加密的文章。有很多!如果要计算哈希值,则不应使用SHA1,因为它有缺陷。请改用SHA2算法。 .Net中有两种实现: SHA256 [ ^ ]和 SHA512 [ ^ ]。 SHA256有一个示例应用程序。


参见 https://msdn.microsoft.com/en-us/library/system.security.cryptography.sha1%28v=vs.110%29.aspx [ ^ ]。

How to use SHA1 Encryption and Decryption algorithm?

解决方案

You don't. SHA is not an encryption algorithm, it is a Hashing algorithm. The difference is that encryption can be reversed to decrypt the data and recover the original input, hashing algorithms cannot - you cannot get the original input back from the output of SHA.

Instead look at something like DES: MSDN[^] - the lkink includes a basic example.


SHA1 is not an encryption-algorithm. It's a hashing algorithm. There's a very clear difference between encryption and hashing: Encrypted data can be decrypted to its original form because during encryption no information is lost, just represented differently. A hash can not be reversed to the original data because that information is lost during the hash computation (at least it should be that way). The goal of a hash is to have a very small "string" that merely represents the original data and can be compared to another hash in order to determine whether or not the source data for these hashes was probably identical or not.

So - what is your intention? If you want to encrypt and decrypt data, SHA1 is no option. I would recommend you to use the search-function of this site to look for articles about encryption. There are a lot! If you want to compute a hash, you should not use SHA1 either because it has flaws. Use a SHA2-algorithm instead. There's are two implementations in .Net: SHA256[^] and SHA512[^]. The SHA256 has a sample application.


See https://msdn.microsoft.com/en-us/library/system.security.cryptography.sha1%28v=vs.110%29.aspx[^].


这篇关于如何使用SHA1加密和解密算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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