无法进行C#Restful身份验证(API Key / Secrete正确)

时间:2017-06-22 11:33:06

标签: c# rest web http-post restful-authentication

我想将经过身份验证的JS(下面)的REST请求转换为C#代码 - 使用RestSharp lib(如图所示)我似乎没有正确构建签名。请帮忙..

休息响应通过"无效的API密钥" (确认密钥/密钥正确无误)保持响应

// sample code using the crypto lib to build the RESTFUL request
const crypto = require('crypto')
const request = require('request')

const apiKey = 'test'
const apiSecret = 'test'
const url = 'version/auth/abc'
const nonce = Date.now().toString()
const body = {}
const rBody = JSON.stringify(body)

// try build the RESTFUL signature here using crypto lib and use sha384

// Not quite sure what's the update does here though.
let signature = `/api/${url}${nonce}${rBody}`
signature = crypto
  .createHmac('sha384', apiSecret)
  **.update(signature)**
  .digest('hex')

// all code above is fine. And this is the sample code only, and trying to do something same in C# and have tried the following. I believe is the way create the "signature" issue.

我已经在下面编写了C#代码,但是没有工作,请指出,我猜这个签名建筑是不正确的。

// sample code using the crypto lib to build the RESTFUL request
const crypto = require('crypto')
const request = require('request')

const apiKey = 'test'
const apiSecret = 'test'
const url = 'version/auth/abc'
const nonce = Date.now().toString()
const body = {}
const rBody = JSON.stringify(body)

// try build the RESTFUL signature here using crypto lib and use sha384

// Not quite sure what's the update does here though.
let signature = `/api/${url}${nonce}${rBody}`
signature = crypto
  .createHmac('sha384', apiSecret)
  **.update(signature)**
  .digest('hex')

// all code above is fine. And this is the sample code only, and trying to do something same in C# and have tried the following. I believe is the way create the "signature" issue.

希望这很清楚。提前谢谢。

0 个答案:

没有答案