Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 131,633 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,294 people online right now. Registration is fast and FREE... Join Now!




SHA Hash Problems in VB

 
Reply to this topicStart new topic

SHA Hash Problems in VB, Problems using SHA Hasing algorithm.

daviddolphin
post 13 Oct, 2008 - 05:42 AM
Post #1


New D.I.C Head

*
Joined: 13 Jun, 2008
Posts: 6


My Contributions


Hi all.

I am trying to right a SHA hasing algorithm to store passwords in a database.

This is the code I am using:

CODE

Dim UE As UnicodeEncoding = New UnicodeEncoding

        Dim HashValue As Byte(), MessageBytes As Byte() = UE.GetBytes(txtPre.Text)

        Dim SHhash As New SHA256Managed()

        Dim strHex As String = ""

        HashValue = SHhash.ComputeHash(MessageBytes)
        For Each b As Byte In HashValue
            strHex += [String].Format("{0:X2}", b)
        Next

        txtPost.Text = strHex


However, the result that this produces differs from convertors I have found online.
Such as:
http://www.geektimedesign.com/tools-SHA-generator.cfm

The difference in results is like this:

185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969
A07E4F7343246C82B26F32E56F85418D518D8B2F2DAE77F1D56FE7AF50DB97AF

For "Hello"

With the websites generated SHA being the first and mine being the second.

Can anyone help me understand what is going on here, as I am at a total losssss!

Thank you much,
David
User is offlineProfile CardPM

Go to the top of the page


PsychoCoder
post 13 Oct, 2008 - 06:31 AM
Post #2


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,906



Thanked 116 times

Dream Kudos: 8450

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Try using SHA1CryptoServiceProvider instead of SHA256Managed, I believe that will give the results you are looking for.

Here's an example of using the SHA1CryptoServiceProvider

vb

''' <summary>
''' method to hash the users password. To match the CAPICOM hash
''' we convert the string to UNICODE first
''' </summary>
''' <returns></returns>
Public Function HashString(ByVal str As String) As String
'create our SHA1 provider
Dim sha As SHA1 = New SHA1CryptoServiceProvider()
Dim hashedValue As String = String.Empty
'hash the data
Dim hashedData As Byte() = sha.ComputeHash(Encoding.Unicode.GetBytes(str))

'loop through each byte in the byte array
For Each b As Byte In hashedData
'convert each byte and append
hashedValue += String.Format("{0,2:X2}", b )
Next

'return the hashed value
Return hashedValue
End Function


Hope that helps smile.gif
User is offlineProfile CardPM

Go to the top of the page

daviddolphin
post 13 Oct, 2008 - 08:43 AM
Post #3


New D.I.C Head

*
Joined: 13 Jun, 2008
Posts: 6


My Contributions


The code you provided results in the same code I can produce with my code upon changing it to SHA1.

However, this code does not correspond to code generated by ANY online SHA Hash generator.

...Any ideas?

I am just concerned with future repeatability and standardization.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 05:38AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month