Sharing data between php and node.js via cookie securely

I have a PHP site, and for real time updates and chat I have installed Node.js and its running fine.

Both PHP and Node.js have access to the same MySQL database.

But the problem is to verify the identity of an user, who is already logged in to the PHP site.

I don't want to talk to the PHP app via any means, REST or not. As, to me this will defeat the same purpose of using Node.js, as then each Node.js request, a new PHP page request would be made.

What I want is, a encryption and decryption method which is understood by both PHP and node.js

So that I can set a cookie with the encrypted value for Node.js request, which will be at updates.mydomain.com subdomain. By reading the cookie, Node.js can decrypt its value and verify the user's identity.

So, my question: is there any encrypt and corresponding decrypt method that is supported via both PHP and Node.js, using same encryption key?

Updates

Actually i m not looking forward to decrypt it on client side :D as then the whole point of decryption is pointless. What i want to do is-

1) PHP to generate a cookie encrypted user info and use that cookie for a specific domain like updates.mydomain.com

2) Then node.js will get the cookie for each subsequent request, and decrypt the data on server side, using the same encryption key.

As u can see, that is why i wanted to know, if there is a common encryption/decryption system between PHP and node.js, so that encrypted data by one can be decrypted by the other and vice versa.

This way i can securly transfer the current logged in users identity from PHP to node.js and i don't have to worry about session management of other kinds :)

So in short, Encrypt by PHP -> Decrypt by Node.js -> get back same data. Possible?

Thanks,
Anjan

11
задан anjan 4 May 2011 в 17:53
поделиться