Asp.net SHA256 problem

A

atakan

Hi

I'm trying to hash a password by using SHA256Managed but it returns wrong
hash.

for "123123" the SHA256 must return
"96cae35ce8a9b0244178bf28e4966c2ce1b8385723a96a6b838858cdd6ca0a1e" but it
returns
"eUFcNsFFljNAhC8b5OnauOs0o0txyAUB/b0QTmDRTN0="

Why this difference occurs in SHA256Managed namespace ?

the code I used is below

Dim txtPass As String
Dim HashValue() As Byte
Dim UE As New System.Text.UnicodeEncoding
Dim ContentBytes As Byte()
Dim oSHA As New SHA256Managed
ContentBytes = UE.GetBytes(txtPassword.Text.ToString)
HashValue = oSHA.ComputeHash(ContentBytes)
txtPass = Convert.ToBase64String(HashValue)

regards
Atakan
 
A

atakan

In microsoft.public.tr.dotnet group Cenk Iscan has solved the problem.
To use SHA256 you can use following sample

Dim txtPass As String
Dim HashValue() As Byte
Dim UE As New System.Text.UTF7Encoding
Dim ContentBytes As Byte()
Dim oSHA As New SHA256Managed
ContentBytes = UE.GetBytes("123123")
HashValue = oSHA.ComputeHash(ContentBytes)
For Each chars As Byte In HashValue
If Len(Hex(chars).ToString) = 1 Then
txtPass &= "0" & Hex(chars).ToString
Else
txtPass &= Hex(chars).ToString
End If
Next
txtPass = LCase$(txtPass).ToString

regards
Atakan

news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top