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:

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
Member Avatar


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


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


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

 RichTextBox1.Text = hexString


commented: Thanks for the help! +0
Member Avatar


How about marking it as solved.