Hey, so I'm creating a program that creates a SHA512 hash. I have a problem though. I try to encrypt the word 'test' and I get this encrypted hash as:
?&??J??I????
???a??w.G?????
?z???????O????{72??_???oW?

Which isn't a SHA512 hash. Here is my code so far, maybe you can help me.

Imports System.Security.Cryptography
Imports System.Security
Imports System.Text
Public Class Form1
    Dim sham As New SHA512Managed()
    Dim result As Byte()
    Dim data As Byte()

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        data = ASCIIEncoding.ASCII.GetBytes(TextBox1.Text)
        result = sham.ComputeHash(data)
        RichTextBox1.Text = ASCIIEncoding.ASCII.GetString(result)
    End Sub
End Class

Recommended Answers

All 6 Replies

Member Avatar for Unhnd_Exception

Why is that not a Sha512 Hash?

It computes a Hash of 64 bytes.

Well when I use the same text on an online hash maker, it generates: ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff

Member Avatar for Unhnd_Exception

You can change the Encoding to get a different output.

A hash is a hash though. As long as you use the same encoding.

Heres an example that will give you a different output.

Dim UE As New UnicodeEncoding()

 data = UE.GetBytes(TextBox1.Text)
 result = sham.ComputeHash(data)
 RichTextBox1.Text = UE.GetString(result)

It looks like your example converts the bytes to hex.

If your not concerned about matching the online hash maker, Your still producing a sha512 hash.

Member Avatar for Unhnd_Exception

Like I was saying, It looks like your example converts the bytes to hex.

This will yeild the same result of your online hash.

data = ASCIIEncoding.ASCII.GetBytes(TextBox1.Text)
 result = sham.ComputeHash(data)

 Dim hexString As String = String.Empty
 For i = 0 To UBound(result)
     hexString &= Hex(result(i)).ToLower
 Next

 RichTextBox1.Text = hexString

ee26b0dd4af7e749aa1a8ee3c1ae9923f618980772e473f8819a5d494edb27ac185f8a0e1d5f84f88bc887fd67b143732c34cc5fa9ad8e6f57f5028a8ff

commented: Thanks for the help! +0

Thank you very much :)

Member Avatar for Unhnd_Exception

How about marking it as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.