HMACSHA256 returns different result on some PC

  • Thread starter Thread starter Skypea
  • Start date Start date
S

Skypea

Guest
Hi! I am creating a client chat application that using HMAC256 for the encryption. This is the sample code:

Module Module1

Sub Main()
Dim encryptedData As String = "ODZjZmNmZmNmZTlkOGMxNS4tLTEzYywiGn9J3AqyAFPz2mDuMvagQzSdhjDBLxwgsVrJtaPLBJjZtZRBUZqwRJVfhGVqE/RNb+G0b/aZ8C4Sy8JtqafqWgNnPCcJGAisHYDQkOa6W5LsIXs/Jy35WTrHkssVnH0hL0PZv8pDCtWvCFuxoaP1"
Dim myKey As String = "iqTrNtQfQu7yKSW4y4VDh06X5N18ZM8qQr2nrC+fYmo="

readBinary(Convert.FromBase64String(encryptedData), Convert.FromBase64String(myKey))
End Sub

Private Sub readBinary(data() As Byte, key() As Byte)
Dim dataText As String = Encoding.Default.GetString(data)
Dim dataPart() As String = dataText.Split({","c}, 2)

Try
Dim encData() As Byte = Encoding.Default.GetBytes(dataPart(1))
Dim hmac As New HMACSHA256(key)
hmac.ComputeHash(encData.ToList.GetRange(32, encData.Length - 32).ToArray)
If Not hmac.Hash.SequenceEqual(encData.Take(32).ToArray) Then
Console.WriteLine("Result doesn't match")
Else
Console.WriteLine("Success")
End If
Catch ex As Exception

End Try
End Sub

End Module

The problem is. I have tested it with 4 PC with different OS. 3 of them (using windows 7/10/Server 2012 R2 all x64 bit) resulting "Success", but one of my PC (PC no. 4) returns "Result doesn't match" that PC runs windows 10 x64 with NET Framework 4.8.03752 Release 528040 (from regedit) the CPU is intel Xeon E-2224G.

I don't know why the result are different. I have test it on my another windows 10 PC too (CPU core i3 with Net Framework 4.8.03761 528049) and the result are "Success".

Any solution please?

Continue reading...
 

Similar threads

C
Replies
0
Views
113
Claude du Québec
C
I
Replies
0
Views
153
Innovators World Wide
I
Back
Top