views:

258

answers:

3

Hi All,

I want to encrypt password in JQuery and decrypt it in servlets. Please tell me which algorithm should I use and how to implement this thing.

A: 

A simple spot of Googling would have got you the answer. The available algorithms seem to be Blowfish, SHA and Rc4. If you want decryption blowfish would be the way to go. For smaller datasets you can use rc4.

For a practical example look at how Yahoo does its logins. The login form has a hidden field which acts as the salt called ".challenge", this is embedded in the hash as follows: fullhash=MD5(MD5(passwd)+challenge)

whatnick
SHA is not encryption but hashing, so you cannot use that. Blowfish, AES, RC4, tripleDES are the most common encryption algorithms
Henri
@Henri: I would rather hash a password than encrypt in terms of web pages.
Zed
@Henri: I was just commenting on the available plugins for Jquery and @Zed yes hashing is the way to go. The OP might just want to be able to recover the passwords.
whatnick
One-way hashes are not enough. You must use some form of asymmetric cypher such as RSA. You can can combine RSA with a one-way hash, but RSA (or similar) must be part of the package, otherwise an attacker can hack your site (from a cryptographic point of view)
Steve
Steve: support your assertions. A one-way hash is perfectly secure for this sort of thing if it's properly salted. MD5 might be a bit broken, but SHA or any of the more modern ones aren't.
Paul McMillan
A: 

This is a classic encryption problem. The one-way hashes described by whatnick will work but there are security issues. Notably an attacker can perform a replay attack as the hash cannot be salted, meaning the user can only ever send the one hash that corresponds to the hast stored in the database. In other words, this is almost the same thing as sending the password in plain text.

The only way to do this properly is with a non-symmetric public key cypher such as RSA. I have seen a Javascript implementation here. I would argue that this is more complicated than necessary and that just doing a secure login via SSL is most probably the safest and easiest thing in the long run.

Steve
You have a failure of imagination. Look at James' post.
Paul McMillan
+3  A: 

You want to use HMAC.

Basically, you send 2 salts to the client. You store in your database

md5(salt + pwd)

you send a unique salt2 and the db salt to the end user, who returns

md5(salt2 + md5(salt + pwd))

and then you compare to that same operation server-side.

As long as you vary the salt sent and don't accept old ones, it is about as secure as you're going to get without SSL. You definitely don't want to try to use AES or RSA anything similar.

If you don't like md5, use any other hashing algorithm of your choice.

James
Just as I was adding the yahoo sample.
whatnick
Clever. Live and learn!
Steve