eddelbuettel / digest

R package to create compact hash digests of R objects
https://eddelbuettel.github.io/digest
111 stars 47 forks source link

digest() in base64 #52

Closed matiasdecarli closed 7 years ago

matiasdecarli commented 7 years ago

I'm porting a piece of code from nodejs to R

Node:

let kDate = crypto.createHmac('sha256', key);
kDate.update(private);
# kDate is a2a786d16d0e23d735ddc931ebe0cb0e4127c86d9c31a280df2c292caaf57385

R:

kDate <- hmac(key = key, object = private, algo = "sha256", raw = FALSE)
# kDate is a2a786d16d0e23d735ddc931ebe0cb0e4127c86d9c31a280df2c292caaf57385

Which is OK, so far so good. The value matches, but then I need to do this in node

kDate_val=kDate.digest('base64');

Is there any easy way to implement this? Since digest() doesnt support base64 and exporting in other methods and converting to base64 don't work either

Thanks in advance

eddelbuettel commented 7 years ago

Sorry, can you rephrase your question? I am not sure what the goal is -- what is kDate.digest() supposed to do? What is kDate?

The digest package really (really !!) is not for cypto or security. We have other packages in the R world for this. digest "merely" computes hash fingerprints. hmac() is a contributed function.

matiasdecarli commented 7 years ago

Yes, sorry. According to the node documentation, digest() does the following

Calculates the HMAC digest of all of the data passed using hmac.update()

kDate holds the value of createHmac right now.

My ultimate goal is to obtain a signing key to use a web service

eddelbuettel commented 7 years ago

hmac() was motivated for something loosely related -- if memory serves it was for a handshake with a db backend. But we have nothing ready-made or pre-cooked for you. You may have put a few pieces together by hand. I think your main problem right now is that you want node's crypto module, and you seem to assume that digest is supposed to deliver all of it. That is however not our purpose here.

Maybe have a look at the Web Technologies Task View; maybe it has something that can help you. I think I will close this issue though.

matiasdecarli commented 7 years ago

Ok, thanks @eddelbuettel for the help