从编码的字节字符串中解密字符串 [英] Decrypt the string from the encoded byte string

查看:85
本文介绍了从编码的字节字符串中解密字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用SHA1算法将字符串转换为加密形式.如何在原始字符串中解密?

代码如下:

I have converted a string in encrypted form using SHA1 algorithm. How do I decrypt it in the original string?

The code is given below:

byte[] data = Encoding.Unicode.GetBytes(TxtAddress.Text);
               SHA1 sha = new SHA1CryptoServiceProvider();
               byte[] hash = sha.ComputeHash(data);
               DSASignatureFormatter DSAFormatter = new DSASignatureFormatter(DSA);
               DSAFormatter.SetHashAlgorithm("SHA1");

               signature = DSAFormatter.CreateSignature(hash);

               string digiSignature = "";
               foreach (byte b in signature)
               { digiSignature += b; }

推荐答案


SHA1不是加密算法,因此无法对其进行解密.正如Seveneyeeyesh所说,它是一个哈希(校验和).它是单向的,无法撤消.

因此,您不能哈希函数 [ .NET中使用TripleDESCryptoServiceProvider类的加密/解密功能 [ ^ ]
使用C#简单加密和解密数据 [ ^ ]
祝一切顺利.
--Amit
Hi,
SHA1 is not an encryption algorithm, so it is not possible to decrypt it. As seventheyejosh just stated, it is a hash (checksum.) And it is one-way and cannot be undone.

So, you Can''t, Hash Function[^] are one way functions. this is why it is used for passwords, because you can''t get the password using some reverse function on the hash value.

You can refer these links for the other solution:
Encryption/Decryption Function in .NET using the TripleDESCryptoServiceProvider Class[^]
Simple encrypting and decrypting data in C#[^]
All the best.
--Amit




请通过如何:使用MD5和SHA1哈希数据 [ ^ ]

这可能对您有帮助,
让我知道您是否有任何疑问.

谢谢
-Amit
Hi,

Please go through How To: Hash Data Using MD5 and SHA1[^]

This may help you,
Let me know if you have any query.

Thanks
-Amit


就像其他人所说的那样,您不能将哈希返回原始数据-这不是哈希函数的目的

也就是说,您似乎正在做的是创建一个数字签名,该签名使用非对称密钥来加密哈希值.

检查数据是否正确是对原始数据进行哈希处理,对哈希进行非对称解密并检查两个哈希的一种情况.

As others have stated, you cannot turn a hash back into it''s original data - that is not the purpose a hash function

That said, what you appear to be doing is creating a digital signature, which uses an asymmetric key to encrypt the hash

Checking the data is correct is a case of hashing the original data, asymmetrically decrypting the hash, and checking the two hashes

PKI[^]


这篇关于从编码的字节字符串中解密字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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