The ComputeHash function's return value is an array of
bytes. In .NET 1.1, the most significant bit of each byte is disregarded when
the Encoding.ASCII.GetString function is called. But this is not true in .NET
2.0. So, to simulate the behavior of Encoding.ASCII.GetString as it worked in
.NET 1.1, I had to get rid of the most significant bit manually in the .NET 2.0
code by ANDing every byte with the binary value of 01111111 (127 in decimal).
The code becomes as follows:
Listing 2
Function ComputeHashValue(ByVal Data As String) As String
Dim HashAlgorithm As SHA1 = SHA1.Create
Dim HashValue() As Byte =
HashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(Data))
REM: Looping over the array and ANDing each byte with 0111111
For i As Integer = 0 To HashValue.Length - 1
HashValue(i) = HashValue(i) And Convert.ToByte(127)
Next
Return Encoding.ASCII.GetString(HashValue)
End Function