I have a php function that generates an RC4 encrypted string. I would like to decode that string using Node - ideally using the built in Crypto module. But I am unable to do so - I just get a blank string.
The PHP code is here /
My JS code is
crypto = require('crypto');
decipher = crypto.createDecipher("rc4", "MY SECRET KEY");
text = "HELLO";
decrypted = decipher.update(text, "utf8", "hex");
decrypted += decipher.final("hex");
console.log(decrypted);
I don't get any output. I have checked that my OpenSSL implementation has RC4 using openssl list-message-digest-algorithms
I am on OSX 10.8, latest node.
I am open to using another module to decrypt - I tried the cryptojs module but did not figure out how to make it work - gave me errors when I tried RC4.
Thanks
I have a php function that generates an RC4 encrypted string. I would like to decode that string using Node - ideally using the built in Crypto module. But I am unable to do so - I just get a blank string.
The PHP code is here http://code.google./p/rc4crypt/
My JS code is
crypto = require('crypto');
decipher = crypto.createDecipher("rc4", "MY SECRET KEY");
text = "HELLO";
decrypted = decipher.update(text, "utf8", "hex");
decrypted += decipher.final("hex");
console.log(decrypted);
I don't get any output. I have checked that my OpenSSL implementation has RC4 using openssl list-message-digest-algorithms
I am on OSX 10.8, latest node.
I am open to using another module to decrypt - I tried the cryptojs module but did not figure out how to make it work - gave me errors when I tried RC4.
Thanks
Share edited Jun 27, 2016 at 9:40 gevorg 5,0755 gold badges38 silver badges54 bronze badges asked Oct 24, 2012 at 22:44 cyberwombatcyberwombat 40.3k41 gold badges184 silver badges267 bronze badges1 Answer
Reset to default 6Figured it out
First one must use crypto.createDecipheriv otherwise the key is - I believe - md5 hashed instead of used raw.
Secondly the input encoding mut be set to binary.
Third - in my case I was dealing with POST data instead of a hardcoded string and I had to urldecode it - decodeURIComponent() jsut choked - but unescape() with removal of + signs did the trick ex:
var text = unescape((response.post.myvar + '').replace(/\+/g, '%20'))
var crypto = require('crypto');
decipher = crypto.createDecipheriv("rc4", key, '');
decrypted = decipher.update(text, "binary", "utf8");
decrypted += decipher.final("utf8");
console.log(decrypted);