Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的Azure DocumentDB身份验证标头_R_Node.js_Azure_Cryptography - Fatal编程技术网

R中的Azure DocumentDB身份验证标头

R中的Azure DocumentDB身份验证标头,r,node.js,azure,cryptography,R,Node.js,Azure,Cryptography,我正在尝试使用R而不是Microsoft提供的C#和Node.js代码片段为REST API调用生成Azure documentDB auth头 我在将此代码从Node.js转换为R时遇到了一些问题: var crypto = require("crypto"); var key = new Buffer(masterKey, "base64"); var text = "helloworld"; var body = new Buffer(text, "utf8"); var si

我正在尝试使用R而不是Microsoft提供的C#和Node.js代码片段为REST API调用生成Azure documentDB auth头

我在将此代码从Node.js转换为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");
在这种情况下,主密钥可以假定为“abcdefghijklmnopqrsTUVWXyz19284745=”


在R中对主密钥进行sha256哈希,然后对该结果进行base64编码,结果不会返回相同的结果。应采取哪些具体步骤来产生相同的结果?一个缓冲对象或等价物似乎不存在于R中,我可以告诉你。

请考虑下面的代码片段:r:< /p>

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)
库(摘要)
图书馆(base64enc)
万能钥匙