简体   繁体   中英

Azure DocumentDB auth header in R

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 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");

In this case, masterKey can be assumed to be "abcdefghijklmnopqrsTUVWXyz19284745=="

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM