I'm trying to build a bitcoin miner. I have generated the message successfully, but I can't get the double SHA256
correctly. The value I'm getting is incorrect. What is wrong with this code?
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
Dim message_combined as string = "02000000671D0E2FF45DD1E927A51219D1CA1065C93B0C4E8840290A00000000000000002CD900FC3513260DF5BD2EABFD456CD2B3D2BACE30CC078215A907C045F4992E3E5F4A5E747B1B1843F740C0"
Dim sha256 As SHA256 = SHA256Managed.Create()
Dim bytes As Byte() = Encoding.UTF8.GetBytes(message_combined)
Dim hash As Byte() = sha256.ComputeHash(bytes)
Dim stringBuilder1 As New StringBuilder()
For i As Integer = 0 To hash.Length - 1
stringBuilder1.Append(hash(i).ToString("X2"))
Next
' Dim sha256 As SHA256 = SHA256Managed.Create()
Dim sha256_2 As SHA256 = SHA256Managed.Create()
Dim bytes2 As Byte() = Encoding.UTF8.GetBytes(stringBuilder1.ToString())
Dim hash2 As Byte() = sha256_2.ComputeHash(bytes2)
'bytes2 = Encoding.UTF8.GetBytes(bytes)
'hash2 = sha256_2.ComputeHash(bytes2)
Dim stringBuilder2 As New StringBuilder()
For i As Integer = 0 To hash2.Length - 1
stringBuilder2.Append(hash2(i).ToString("X2"))
Next
final_hash = stringBuilder2.ToString()
TextBox9.Text = final_hash
End Sub
After double hashing, the end hash should be: 920F0D3EF835E723DBDA8AE0E1EA0705FAF53AC784A8116639BCB215F3BC9D8B