Guest User

Untitled

a guest
Jun 24th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. Private Shared Function ComputeHashValue(ByVal Data As String) As String
  2. Dim HashAlgorithm As SHA512 = SHA512.Create
  3. Dim HashValue() As Byte = HashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(Data))
  4. ' Looping over the array and ANDing each byte with 0111111
  5. For i As Integer = 0 To HashValue.Length - 1
  6. HashValue(i) = HashValue(i) And Convert.ToByte(127)
  7. Next
  8. Return Encoding.ASCII.GetString(HashValue)
  9. End Function
  10.  
  11. Private Shared Function AreByteArraysEqual(ByVal array1 As Byte(), ByVal array2 As Byte()) As Boolean
  12. If array1.Length <> array2.Length Then Return False
  13. For i As Integer = 0 To array1.Length - 1
  14. If array1(i) <> array2(i) Then Return False
  15. Next
  16. Return True
  17. End Function
  18.  
  19. Private Shared Sub SomeMethod()
  20. Dim t_prvBytes() As Byte = New Byte() {SOME VALUES} 'Previously computed HASH
  21. Dim t_dllStream As New IO.FileStream("C:myfile.txt", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
  22.  
  23. Dim t_reader As New IO.StreamReader(t_dllStream)
  24.  
  25. Dim t_dllHash() As Byte = System.Text.Encoding.Unicode.GetBytes(ComputeHashValue(t_reader.ReadToEnd))
  26.  
  27. MsgBox(AreByteArraysEqual(t_dllHash, t_prvBytes))
  28.  
  29. t_dllStream.Close()
  30. End Function
Add Comment
Please, Sign In to add comment