Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Deciphering Hash Decryption

Status
Not open for further replies.

lucyv

Programmer
Mar 11, 2002
152
US
While researching hash and encryption examples, I stumbled upon a class library that contains functions that can encrypt string data using MD5, SHA1, SHA256, SHA384, and SHA512 algorithms. The code is very neat and clean, and was develped by Guo Xu (
However, the sample code only converts the data to hash, it does not convert the hash back to the original values. I understand the code but I can not figure out how to convert the data back.

Here is a sample of the code:

Code:
Public Class HashLib

    Public Function MD5Hash(ByVal InputStr As String) As String
        Dim MD5Hasher As New System.Security.Cryptography.MD5CryptoServiceProvider
        Return ToHexString(MD5Hasher.ComputeHash(Encoder.GetBytes(InputStr)))
    End Function

    Private Function ToHexString(ByVal ByteArray As Byte()) As String
        Dim i As Integer
        For i = LBound(ByteArray) To UBound(ByteArray)
            ToHexString &= Hex(ByteArray(i))
        Next
    End Function

End Class

Can someone please inform me on how I can convert the hash data back to the original state?

---

By the way, if anyone wants all of the code that was found in this module please let me know. Mr. Guo Xu kindly stated that we can redistribute this code if needed.

-lucyv
 
With a lot of password encryption there is no reason to decrypt the string. In order to check the user entered value you just encrypt it with the same key and compare the encrypted values.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Hashes are one-way functions. You cannot convert a hash value back to its original string (although you can generate a similar string that has the same hash value -- you just need 10^150 CPU cycles to do it)

They're commonly used to store passwords, as you would just compare the stored hash value against the as-entered hash value to see if they match.

If you truly need to decrypt the data, you should use one of the encryption algorithms (such as Rjindael or Triple-DES), and not a hash algorithm.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks for the posts. I'll look into the encrypion algorithms that were suggested.

-lucyv
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top