본문 바로가기
코인/코인원API

코인원 API V2 엑셀 인증을 위해 Hex_HMACSHA512 만들기

by 큐브빌드 2021. 5. 18.
반응형

코인원 API를 엑셀에서 사용하기 위해서 VBA를 사용하여 HMACSHA512 만드는 코드 입니다.

 

두개 함수가 모두 필요합니다.

Public Function Hex_HMACSHA512(ByVal sTextToHash As String, ByVal sSharedSecretKey As String)
Dim asc As Object, enc As Object
Dim TextToHash() As Byte
Dim SharedSecretKey() As Byte
Set asc = CreateObject("System.Text.UTF8Encoding")
Set enc = CreateObject("System.Security.Cryptography.HMACSHA512")
TextToHash = asc.Getbytes_4(sTextToHash)
SharedSecretKey = asc.Getbytes_4(sSharedSecretKey)
enc.Key = SharedSecretKey

Dim bytes() As Byte
bytes = enc.ComputeHash_2((TextToHash))
Hex_HMACSHA512 = ToHexString(bytes)
Set asc = Nothing
Set enc = Nothing
End Function

Function ToHexString(rabyt)
With CreateObject("MSXML2.DOMDocument")
.LoadXML "<root />"
.DocumentElement.DataType = "bin.Hex"
.DocumentElement.nodeTypedValue = rabyt
ToHexString = Replace(.DocumentElement.text, vbLf, "")
End With
End Function
반응형

댓글