R中的Azure DocumentDB身份验证标头 [英] Azure DocumentDB auth header in R
问题描述
我正在尝试使用R而不是Microsoft提供的C#和Node.js代码段来生成用于REST API调用的Azure documentDB auth标头。
I'm attempting to generate the Azure documentDB auth header for REST API calls using R instead of the C# and Node.js code snippets provided by Microsoft.
I 'm特别遇到了将这段代码从Node.js转换为R的问题:
I'm specifically running into issues translating this code from Node.js to R:
var crypto = require("crypto");
var key = new Buffer(masterKey, "base64");
var text = "helloworld";
var body = new Buffer(text, "utf8");
var signature = crypto.createHmac("sha256", key).update(body).digest("base64");
在这种情况下,可以假定masterKey为 abcdefghijklmnopqrsTUVWXyz19284745 ==
In this case, masterKey can be assumed to be "abcdefghijklmnopqrsTUVWXyz19284745=="
对R中的主键进行sha256哈希运算,然后对结果进行base64编码不会返回相同的结果。应该采取哪些具体步骤来生成相同的内容?据我所知,R中似乎不存在缓冲区对象或等效对象。
Making a sha256 hash of the master key in R then base64 encoding that result isn't returning the same result. What specific steps should be taken to generate the same? A buffer object or equivalent doesn't seem to exist in R from what I can tell.
推荐答案
请考虑以下代码片段在R中:
Please consider the following code snippets in R:
library(digest)
library(base64enc)
masterKey <- "your master key here"
key <- base64decode(masterKey)
text <- "helloworld"
body <- enc2utf8(text)
signature <- base64encode(hmac(key, body, algo = "sha256", raw = T))
print(signature)
这篇关于R中的Azure DocumentDB身份验证标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!