This is an oddball question, but I have been working on this for hours now and am not making much progress. I am hoping someone here may be able to advise...
I am porting a script from php to node. The php script makes use of this function:
hash_hmac('sha512', $text, $key);
I have reproduced this in node using the crypto module:
var hash = crypto.createHmac( "sha512", key );
hash.update( text );
return hash.digest( "hex" );
I have verified that these functions produce the same hash when given the same text and key.
Except...
The string that is being used for a key in php looks similar to this: (Don't ask)
define("SITE_KEY", "
__
, ,' e`---o
(( ( | ___,'
\\~-------------------------------' \_;/
( /
/) ._______________________________. )
(( ( (( (
``-' ``-'
");
I have tried to reproduce this in Javascript like so:
var key = "\
__\
, ,' e`---o\
(( ( | ___,'\
\\\\~-------------------------------' \\_;/\
( /\
/) ._______________________________. )\
(( ( (( ( \
``-' ``-'\
\
";
But it doesn't work. (I assume it has to have something to do with the linebreaks).
Replacing the newlines with "\r\n" or "\n" as in the following also does not work:
var key = "\r\n __\r\n , ,' e`---o\r\n (( ( | ___,'\r\n \\\\~-------------------------------' \\_;/\r\n ( /\r\n /) ._______________________________. )\r\n (( ( (( ( \r\n ``-' ``-'\r\n\r\n";
Suggestions on how to fix this? (Getting rid of the dog is not an option, unfortunately.)
Thanks (in advance) for your help.