Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,700 questions

57,013 answers

573 users

How to uniquely identify an array using SHA-256 hash and verify that data has not changed in VB.NET

1 Answer

0 votes
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
' 
'

 



answered 3 days ago by avibootz
...