我该如何计算API中的签名?

时间:2017-10-02 12:35:00

标签: vb.net

我想为yobit创建API。现在,我会做一些非常简单的事情,即获取信息。

在Python中,代码类似于

 url = 'https://yobit.net/tapi'
    values['method'] = method
    values['nonce'] = str(int(time.time()))
    body = urlencode(values)
    signature = hmac.new(self.secret, body, hashlib.sha512).hexdigest()
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Key': self.key,
        'Sign': signature
    }

我基本上想用等效的vb.net替换代码hmac.new(self.secret, body, hashlib.sha512).hexdigest()

这是我目前的代码

Public Overrides Sub readbalances()
    Dim secret = _secret
    Dim url = "https://yobit.net/tapi"
    Dim key = New Tuple(Of String, String)("Key", _apiKey)
    Dim parameters = "method=getInfo&nonce=" + Str(Int(DateTime.Now))
    Dim sig = New System.Security.Cryptography.HMACSHA512().ToString 'What should I put here?
    Dim sigtupple = New Tuple(Of String, String)("Sign", sig)
    Dim result = CookieAwareWebClient.downloadString1("url", {key, sigtupple}, parameters)
End Sub

我该怎么办?

downloadString1的内容如下,但我们只是说它按预期执行

Public Shared Function downloadString1(url As String, headers As Tuple(Of String, String)(), postdata As String) As String
    Dim wc = New CookieAwareWebClient

    For Each header In headers
        wc.Headers.Add(header.Item1, header.Item2)
    Next
    Dim result = wc.UploadString(url, postdata)
    Return result
End Function

0 个答案:

没有答案