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

编程入门 行业动态 更新时间:2024-10-27 04:32:32
本文介绍了如何使用SHA1加密和解密算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

解决方案

你没有。 SHA不是加密算法,它是哈希算法。区别在于可以反转加密来解密数据并恢复原始输入,哈希算法不能 - 你无法从SHA的输出中获得原始输入。 而不是看DES这样的东西: MSDN [ ^ ] - lkink包含一个基本示例。

SHA1不是加密算法。这是一个哈希算法。加密和散列之间存在非常明显的区别:加密数据可以解密为其原始形式,因为在加密期间没有信息丢失,只是表示不同。哈希不能反转为原始数据,因为在哈希计算期间该信息会丢失(至少应该是这样)。散列的目标是拥有一个非常小的字符串,它只代表原始数据,并且可以与另一个散列进行比较,以确定这些散列的源数据是否相同。 那么 - 你的意图是什么?如果要加密和解密数据,则不能选择SHA1。我建议您使用本网站的搜索功能来查找有关加密的文章。有很多!如果要计算哈希值,则不应使用SHA1,因为它有缺陷。请改用SHA2算法。 .Net中有两种实现: SHA256 [ ^ ]和 SHA512 [ ^ ]。 SHA256有一个示例应用程序。

参见 msdn.microsoft/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 msdn.microsoft/en-us/library/system.security.cryptography.sha1%28v=vs.110%29.aspx[^].

更多推荐

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

本文发布于:2023-11-30 10:16:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649622.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   算法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!