Imports System
Imports System.Text
Imports System.Security.Cryptography
Public Module ArrayHashHelper
''' <summary>
''' Computes a SHA-256 hash for an integer array and returns
''' it as a hexadecimal string.
''' </summary>
Public Function GetArraySha256(values As Integer()) As String
If values Is Nothing Then
Return String.Empty
End If
' Convert array to a string representation.
Dim input As String = String.Join(",", values)
' Convert string to bytes.
Dim data As Byte() = Encoding.UTF8.GetBytes(input)
' Compute SHA-256 hash.
Using sha256 As SHA256 = SHA256.Create()
Dim hashBytes As Byte() = sha256.ComputeHash(data)
' Convert bytes to a hexadecimal string.
Dim sb As New StringBuilder()
For Each b As Byte In hashBytes
sb.Append(b.ToString("x2"))
Next
Return sb.ToString()
End Using
End Function
Public Sub Main(args As String())
Dim originalData As Integer() = {1, 2, 3, 4, 5}
Dim originalHash As String = GetArraySha256(originalData)
Console.WriteLine(originalHash)
Dim currentData As Integer() = {1, 2, 3, 4, 5}
Dim currentHash As String = GetArraySha256(currentData)
Console.WriteLine(currentHash)
Dim isSame As Boolean = (originalHash = currentHash)
Console.WriteLine(isSame)
End Sub
End Module
' run:
'
' b726eed184cea30d5a57fb645f77527e4232bec085e24e8d29a6e3b2c84c2db1
' b726eed184cea30d5a57fb645f77527e4232bec085e24e8d29a6e3b2c84c2db1
' True
'
'