Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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; }
Posted

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
 
Share this answer
 
v2
Comments
Member 8491154 14-Jul-12 2:21am    
so what can other solution?
_Amy 14-Jul-12 2:39am    
See my updated answer.
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
 
Share this answer
 
Comments
Member 8491154 14-Jul-12 1:35am    
It does the validation part, but the string is not decrypted back to original string.
AmitGajjar 16-Jul-12 0:02am    
Why you need decrypted text ? if you have login functionality then you do not need to decrypt the password. instead you can encrypt user entered password and your database encrypted password.
Member 8491154 18-Jul-12 3:22am    
I just want to validate the signature generated
AmitGajjar 18-Jul-12 5:09am    
in that case you can compare your stored signature with generated signature.
Member 8491154 18-Jul-12 7:24am    
i am asking that only. How do I compare the signature and hash already stored in database
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900