Link to home
Start Free TrialLog in
Avatar of uxphreak
uxphreak

asked on

Generate a hash from a string

Hello,

I have an old VB 6 application that uses a class to create a hash of a users password which is output and stored in a database.  I need to create a VB.NET 2008 application that needs to compare the hash value in the database but I don't know how to create the function to generate the hash.

The hash is generated from a string consisting of input from the user along with a value appended to the input.  I was told by the vendor who created the class in the VB 6 application that I should use SHA256MANAGED in VB.NET 2008 to generate the hash but they have refused to help me any further than that.  They have provided the VB 6 Class code to me, but with my inexperience I can't make heads or tales of it.  I can attach the code if this helps to determine the solution.

I realize this might be a futile effort but I'm hoping this is less complicated than I fear it is.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of uxphreak
uxphreak

ASKER

Thanks abel, but isn't GetSHA256 just for C#?  I'm using VB and receive an error when using GetSHA256.
SOLUTION
Avatar of oobayly
oobayly
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Developer Fusion has a great tool that translates C# <--> VB.Net
http://www.developerfusion.com/tools/convert/csharp-to-vb/
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for the follow-up on this and filling in the blanks, guys. I was a bit brief and not as complete as I could be. Hope the combination of comments helps the OP :)
Thanks everyone.  Using the comments and suggestions, I tailored my code to suite my needs...
Imports System
Imports System.Text
Imports System.Security.Cryptography
 
Public Class clsEncrypt
 
Public Function SHA256MHash(ByVal strPWD as String) as String
 
        Dim strToHash As String = strPWD & "EIOOWC32KGF02LG"
        Dim SHA256 As New SHA256Managed
        Dim hash() As Byte = sHA256.ComputeHash(Encoding.ASCII.GetBytes(strToHash))
        Dim sb as New Stringbuilder
        Dim outputByte as Byte
        For Each outputByte in hash
            sb.Append(outputByte.ToString("x2").ToUpper)
        Next outputByte
 
        Return sb.ToString.ToLower
 
End Function
 
End Class

Open in new window