https://en.m.wikibooks.org/wiki/Visual_Basic_for_Applications/String_Hashing_in_VBA
도구 추가:
Mscorlib 4.0 64bit
소스:
결과:Function SHA256(sIn As String, Optional bB64 As Boolean = 0) As String'prerequisite'Set a reference to mscorlib 4.0 64-bitDim oT As Object, oSHA256 As ObjectDim TextToHash() As Byte, bytes() As ByteSet oT = CreateObject("System.Text.UTF8Encoding")Set oSHA256 = CreateObject("System.Security.Cryptography.SHA256Managed")TextToHash = oT.GetBytes_4(sIn)bytes = oSHA256.ComputeHash_2((TextToHash))If bB64 = True ThenSHA256 = ConvToBase64String(bytes)ElseSHA256 = ConvToHexString(bytes)End IfSet oT = NothingSet oSHA256 = NothingEnd FunctionFunction ConvToHexString(vIn As Variant) As VariantDim oD As ObjectSet oD = CreateObject("MSXML2.DOMDocument")With oD.LoadXML "" .DocumentElement.DataType = "bin.Hex".DocumentElement.nodeTypedValue = vInEnd WithConvToHexString = Replace(oD.DocumentElement.Text, vbLf, "")Set oD = NothingEnd Function
Base64: MDkBFbBmlo/AYoaEwOl7KAUEnj5dfJ/+1pxVFjKkkuc=44 characters in lengthHex: 30390115b066968fc0628684c0e97b2805049e3e5d7c9ffed69c551632a492e764 characters in length
No comments:
Post a Comment