20
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Excel VBA で SHA256

Last updated at Posted at 2017-01-16

Excel VBA で SHA256

エクセルのマクロでSHA256値を算出します
必要に迫られて検索したら、程よいものがありました
ホント、感謝です

参考サイト: http://www.se-japan.com/memo/vbscript/


Function SHA256(s As String) As String
    Dim objSHA256
    Dim objUTF8
    
    Dim bytes() As Byte
    Dim hash() As Byte
    
    Dim i
    Dim wk
    
    '// INIT
    Set objSHA256 = CreateObject("System.Security.Cryptography.SHA256Managed")
    Set objUTF8 = CreateObject("System.Text.UTF8Encoding")
    
    '// 文字列を UTF8 にエンコードし、バイト配列に変換
    bytes = objUTF8.GetBytes_4(s)
    
    '// ハッシュ値を計算(バイナリ)
    hash = objSHA256.ComputeHash_2((bytes))
    
    '// バイナリを16進数文字列に変換
    For i = 1 To UBound(hash) + 1
        wk = wk & Right("0" & Hex(AscB(MidB(hash, i, 1))), 2)
    Next i
    
    '// 結果を返す
    SHA256 = LCase(wk)

End Function
20
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?