-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Can I encrypt data in node.js and decrypt in PHP? #1067
Comments
This isn't an issue. |
That's an issue. |
Makes me wonder how many other of the 364 "bugs" are just stupid little questions like this. |
@tyler point it out how stupid the question is. show me a working code in both node.js and php. dude. |
@murvinlai hit up #node.js on irc.freenode.org for answers to questions. |
@murvinlai You're basically asking if you can eat a hamburger. |
@tyler, If I have solved it and made it work, i couldn't made a post here. THINK about it. |
@murvinlai, everytime you make a reference to @tyler in this thread, it sends me an email. Please reference @tylermwashburn, not @tyler. Also, for the record, you're misusing GitHub's Issues interface. Issues is for bugs and feature requests. You're asking a question regarding how to use node. Please listen to the advice above and visit #node.js on irc.freenode.org to ask questions. Thanks. |
@tyler Thanks Tyler. :) sorry about the trouble. On Tue, May 31, 2011 at 2:45 PM, tyler <
|
and actually, This may be a bug. I raise the issue because the one that you On Tue, May 31, 2011 at 3:16 PM, Murvin Lai murvinlai@gmail.com wrote:
|
@murvinlai If this is still broken, could you please provide some code as an example of when it doesn't work? It would really help figuring out what is going wrong. |
I will do a test tomorrow. :) On Wed, Jul 6, 2011 at 5:09 PM, zmaril <
|
Excellent, thank you! On Wed, Jul 6, 2011 at 7:20 PM, murvinlai <
|
Doesn't really work. It may be the way I encrypt it. Here is my code: Node.js var text = "Yes"; var cipher = crypto.createCipheriv('aes-256-cbc', encryption_key, iv); and here is the PHP: the output don't match and I can't decrypt in nodejs->php or php->node.js |
This is what I get from the node code: Here is what I get from the PHP code: They are different, but I don't know why. I don't know enough php/node to really know whether the two code snippets are trying to do the same thing or whether there is something different between them. Wish I could help more. |
|
@murvinlai - is this still an issue for you? |
It still failed with my latest test on v0.4.9 last week. I will try again tmr. Sent from Murvin's iPhone On 2011-07-24, at 2:02 PM, bnoordhuisreply@reply.github.com wrote:
|
It is still a problem. The encrypted data in PHP & Node.js are different. thus, you cannot encrypt with one language and decrypt in another language. |
Php pads with null bytes, perhaps that's why you see different output. |
I don't see any updates here. I'm closing this as a non-issue until I see a real failing test-case. |
I have the same problem with nodejs 10.5, php can decode nodejs eccode data, but nodejs can not decode php encode data. |
Please post example. |
Here's one basic issue. Openssl implements a limited form of Rijndael as specified by AES, with a block size of 128 bits. PHP binds to libmcrypt, which implements a more generic form of Rijndael. The constant As a solution for those wishing to bridge the gap between PHP and Node.js (or some other environment which uses libmcrypt), I created node-rijndael which binds to libmcrypt and provides limited functionality for encrypting and decryption rijndael with a block size of 256 bits. If you're using this in PHP mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $plaintext, MCRYPT_MODE_ECB);
mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $ciphertext, MCRYPT_MODE_ECB); You can do the same in Node: var rijndael = require('node-rijndael');
// straight through (must be buffers)
rijndael.encrypt(plaintext, key);
rijndael.decrypt(ciphertext, key);
// or bound (can take a string for the key and an encoding)
var rijn = rijndael(key);
rijn.encrypt(plaintext); // gotta be a buffer again for implementation simplicity
rijn.decrypt(ciphertext); |
Hi @murvinlai ! |
Hi @inieto. Thanks. I will take a look. I remembered that at last I used some other ways to achieve that encrypt & decrypt across node & PHP |
If I have the same key, can I encrypt data in node.js using built in crypt lib, with AES-256-CBC, then decrypt it in PHP?
if so, should I juse RIJNDAEL-256 or RIJNDAEL-128? what I should set for iv in PHP decryption?
The text was updated successfully, but these errors were encountered: