I am encrypting a large text file. I am getting a hash value before in encryption and then attaching the hash value to the file though the encryption stream as the last part. I then am decrypting the file, attempting to extract the hash value and compare it to a hash value of the file after it has been decrypted. I am also keeping the old hash vlue temporarly to see how they all three compare. Now, the character count is the same except for the before and after encrypt/decrypt phase except that the decrypted file with the hash still on is 21 characters longer than the original, not 20 as I expected. So, not if I take off just the original file protion, use the same hash algorithm on it that I did the original file and then compare it to the hash value at the end of the file and the original hash value, all of these should in theory by the same. Well for some reason, they are all three coming up different. Here is my code where I read the decrypted file and extract the hash code, etc... I still do not see where my problem is.
Thanks for the help.
Chester
Code:
Try
Dim hashSHA1 As New SHA1CryptoServiceProvider
Dim objNewFile As FileStream = New FileStream("C:\TestCode\tblDetlBBB.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
Dim objFileName As FileStream = New FileStream(strOutputDecrypt, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Dim rdr As New StreamReader(objFileName)
Dim wrt As New StreamWriter(objNewFile)
Dim sArray As Byte() = (New UnicodeEncoding).GetBytes(rdr.ReadToEnd)
Dim hashsize As Integer = hashSHA1.HashSize / 8
Dim msNewStream As New MemoryStream
Dim msStreamHass As New MemoryStream
msNewStream.Position = 0
msNewStream.Write(sArray, 0, sArray.Length - hashsize)
msStreamHass.Write(sArray, sArray.Length - hashsize, hashsize)
Dim newHash As Byte() = hashSHA1.ComputeHash(msNewStream)
Dim oldhash As Byte() = msStreamHass.ToArray
Dim A, B, C As Integer
For i As Integer = 0 To hashsize - 1
A = bytHash(i)
B = oldhash(i)
C = newHash(i)
MessageBox.Show(A & " " & B & " " & C)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Thanks for the help.
Chester