Skip to content

Instantly share code, notes, and snippets.

@kaugesaar
Created February 14, 2024 16:58
Show Gist options
  • Save kaugesaar/53504eed1f29eff9a1bda375751ff24d to your computer and use it in GitHub Desktop.
Save kaugesaar/53504eed1f29eff9a1bda375751ff24d to your computer and use it in GitHub Desktop.
SHA256 Excel Formula
Function SHA256Hash(Text As String) As String
Dim asc As Object
Dim enc As Object
Dim TextBytes() As Byte
Dim HashBytes() As Byte
Dim i As Integer
Set asc = CreateObject("System.Text.UTF8Encoding")
Set enc = CreateObject("System.Security.Cryptography.SHA256Managed")
TextBytes = asc.GetBytes_4(Text)
HashBytes = enc.ComputeHash_2((TextBytes))
SHA256Hash = ""
For i = 0 To UBound(HashBytes)
SHA256Hash = SHA256Hash & LCase(Right("0" & Hex(HashBytes(i)), 2))
Next i
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment