There is an Excel module, taken from here https://en.wikibooks.org/wiki/Visual_Basic_for_Applications/String_Hashing_in_VBA :
Public Function SHA256h(sIn As String) As String Dim oT As Object, oSHA256 As Object Dim TextToHash() As Byte, bytes() As Byte Set oT = CreateObject("System.Text.UTF8Encoding") Set oSHA256 = CreateObject("System.Security.Cryptography.SHA256Managed") sIn = Converthex(sIn) 'дополнено' TextToHash = oT.GetBytes_4(sIn) bytes = oSHA256.ComputeHash_2((TextToHash)) SHA256h = ConvToHexString(bytes) Set oT = Nothing Set oSHA256 = Nothing End Function Private Function ConvToHexString(vIn As Variant) As Variant Dim oD As Object Set oD = CreateObject("MSXML2.DOMDocument") With oD .LoadXML "<root />" .DocumentElement.DataType = "bin.Hex" .DocumentElement.nodeTypedValue = vIn End With ConvToHexString = Replace(oD.DocumentElement.Text, vbLf, "") Set oD = Nothing End Function But the result does not suit me. I apply to the lines in Excel, I get: SHA256h (11) = 4fc82b26aecb47d2868c4efbe3581732a3e7cbcc6c2efb32062c08170a05eeb8
I want to get the result: SHA256h (11) = 4a64a107f0cb32536e5bce6c98c393db21cca7f4ea187ba8c4dca8b51d4ea80a
How to adapt this code to another type of input data? I check on http://www.fileformat.info/tool/hash.htm
The only thing that was found was an additional function:
Private Function Converthex(strHexString As String) As String Dim intLenOfString As Integer Dim intCounter As Integer Dim strBuild As String If Len(strHexString) = 0 Or Len(strHexString) Mod 2 <> 0 Then Exit Function intLenOfString = Len(strHexString) For intCounter = 1 To Len(strHexString) If intCounter Mod 2 <> 0 Then strBuild = strBuild & Chr$(Val("&H" & Mid$(strHexString, intCounter, 2))) Converthex = strBuild End If Next End Function It gives almost the desired result. But not for hex letters with "letters": sha256h (FF) = 8a8de823d5ed3e12746a62ef169bcf372be0ca44f0a1236abc35df05d96928e1
And should sha256h (FF) = a8100ae6aa1940d0b663bb31cd466142ebbdbd5187131b92d93818987832eb89
Poke your nose. What am I doing wrong, and where to dig? (The length of my messages is about 160 bytes)
4a64a107f0cb32536e5bce6c98c393db21cca7f4ea187ba8c4dca8b51d4ea80a- is this a hash for what? - Zergatul