Swift - HMAC SHA512 - 签名无效

时间:2018-06-01 17:43:58

标签: ios swift encryption alamofire hmac

我正在尝试使用Bittrex API(找到here

但是我总是得到回应:

SUCCESS: {
    message = "INVALID_SIGNATURE";
    result = "<null>";
    success = 0;
}

这就是我的代码:

//NONCE
let timeInterval = NSDate().timeIntervalSince1970
let nonceTime = String(Int(floor(timeInterval)))
//STANDARDS
let paras:Parameters = ["apikey": key, "nonce": nonceTime]
let uri = "https://bittrex.com/api/v1.1/account/getbalances?apikey=\(key)&nonce=\(nonceTime)"
//SIGN
let secretKey = HMAC(algorithm: .sha512, key: uri).update(string: secret)!.final()
let skey = String("\(secretKey)")
//HEADER
let headers:HTTPHeaders = ["apisign": "\(skey)"]
let getMethod:HTTPMethod = .get

Alamofire.request(uri, method: getMethod, parameters: paras, encoding: JSONEncoding.default, headers: headers).responseJSON { (response) in
    print("\(response)")
}

有人知道我做错了什么吗? 对于HMAC,我正在使用IDZSwiftCommonCrypto

0 个答案:

没有答案