How to encrypt w/PHP then decrypt w/JavaScript?

I am writing a client-side DHTML app that I want to limit its use by an expiration key.

Obviously this is more of a deterrent than top-shelf software protection, but it will suffice if I can actually pull it off because its users are low-risk candidates (unlikely hackers).

The code will be obfuscated. It uses Google Gears for its local data services. Its manifest file should download an encrypted string containing a date after which the script will lock-up and promote the user to my server.  The server will be running PHP and should, upon a successful purchase respond with a new encrypted date string that the obfuscated client code will then update and start working again.

I'm pretty confident about the idea, but in practice I don't know how to have PHP generated a string of encrypted text which JavaScript can then decrypt.

Any general direction for doing so would be most greatly appreciated.  This probably isn't a common request.

So basically, how do I get started?
MariettaCellarsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VanHackmanCommented:

You need a bidirectional Encryption algorithm supported for both, php and javascript.

In php you have a lot of  Encryption algorithms ready to use, but in javascript as you know is a complete different story... so What can we do?...

1 - Implement your own bidirectional encryption algorithm with "simple" code that you can implement in Javascript and php.

2- Using Base64 encryption, it is already implemented in php with the base64_encode() function, and in javascript:

http://www.webtoolkit.info/javascript-base64.html    ( Ta daaaa!... )

So... you can get what you need esily just using the base64_encode() php function to encrypt and the base64 decode function in Javascript do decrypt =)

WARNING: Base64 is a very popular and easy to reconigze/decrypt encryption algorithm, so you must take some extra security preventions, like obfuscate the javascript decoding function, and add some prefix to the encrypted data.

Let me know if my answer helps you.  

~VanHackman

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VanHackmanCommented:

The solution is in my post ID:26089302 Date:12/19/09 06:30 PM, there are not another way to solve the problem that the options that I have provided.

I have posted links for code examples too, so MariettaCellars have enough resources to code the solution.

~VanHackman
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Encryption

From novice to tech pro — start learning today.