|
-
Jan 23rd, 2008, 05:45 PM
#1
Thread Starter
Lively Member
[RESOLVED] [2005] SHA-1/MD5 hash values odd
I am having a strange issue with the SHA-1 and MD5 values from files. using the below code computing the value for the same file I get the following values:
MD5 - F7ABA96EFC684E3E75EEE8C3E46DDFA
SHA-1- 714E16482F18EBDBCD6B72FC1B0536CF0DC5B72
My issue is when i compute the hash values using Microsoft's FCIV.exe tool, or other tools that compute the values they have some extra zero's that my tool does not have. here is what the FCIV.exe tool outputs.
MD5 - 0f7aba96efc684e3e75eee8c3e46ddfa
SHA-1- 714e16482f18eb0dbcd6b72fc1b0536cf0dc5b72
Does anyone know why there is an extra zero in the output from the other tools or why my code is not putting them in?
MD5
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Not (Me.OpenFileDialog1.FileName = String.Empty) Then
Dim f As New System.IO.FileStream(Me.OpenFileDialog1.FileName, IO.FileMode.Open)
Dim md5 As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim hash As Array
Dim md5Hash As String
Dim sb As New System.Text.StringBuilder
md5.ComputeHash(f)
hash = md5.Hash
For Each hashByte As Byte In hash
sb.Append(String.Format("{0:X1}", hashByte))
Next
md5Hash = sb.ToString
f.Close()
Me.TextBox2.Text = sb.ToString
End If
End Sub
SHA-1
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not (Me.OpenFileDialog1.FileName = String.Empty) Then
Dim f As New System.IO.FileStream(Me.OpenFileDialog1.FileName, IO.FileMode.Open)
Dim sha As New System.Security.Cryptography.SHA1CryptoServiceProvider
Dim hash As Array
Dim shaHash As String
Dim sb As New System.Text.StringBuilder
sha.ComputeHash(f)
hash = sha.Hash
For Each hashByte As Byte In hash
sb.Append(String.Format("{0:X1}", hashByte))
Next
shaHash = sb.ToString
f.Close()
Me.TextBox2.Text = sb.ToString
End If
End Sub
-
Jan 23rd, 2008, 09:34 PM
#2
Re: [2005] SHA-1/MD5 hash values odd
Run this code and you should find your answer:
Code:
Dim b1 As Byte = 255
Dim b2 As Byte = 15
MessageBox.Show(b1.ToString("X1"), "X1")
MessageBox.Show(b2.ToString("X1"), "X1")
MessageBox.Show(b1.ToString("X2"), "X2")
MessageBox.Show(b2.ToString("X2"), "X2")
-
Jan 23rd, 2008, 11:33 PM
#3
Thread Starter
Lively Member
-
Jan 23rd, 2008, 11:44 PM
#4
Re: [RESOLVED] [2005] SHA-1/MD5 hash values odd
You shouldn't really be using:
vb.net Code:
String.Format("{0:X2}", hashByte)
but rather:Either way though, the result is the same. "X2" is the format string. The "X" means the number will be formatted as hexadecimal in upper case, while the "2" means the result should be padded to 2 digits with leading zeroes if required.
If you don't know how String.Format works then try executing this code and it should make it clear:
vb.net Code:
Dim aString As String = "Hello World" Dim aNumber As Integer = 100 Dim aDate As Date = Date.Now MessageBox.Show(String.Format("0={0}, 1={1}, 2={2}, 0={0}", _ aString, _ aNumber, _ aDate))
-
Jan 24th, 2008, 12:15 PM
#5
Thread Starter
Lively Member
Re: [RESOLVED] [2005] SHA-1/MD5 hash values odd
You're a gentleman and a scholar...thanks again my friend for all the help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|