0
  1. I have a Rails WebServer based on REST API
  2. I have a AngularJS app, which connects to this WebServer

What is the best way to encrypt login and password on client side and decrypt these credentials on server side?

2
  • You can't do this in javascript because everything the javascript code is doing can be easily detected over the wire. If you want to send encrypted credentials you should use HTTPS. Commented Feb 17, 2014 at 18:47
  • Yes, I know. On the very end we'd like to use TSL to secure our connection, but for now, we have to rely on standard HTTP so we want to encrypt our data in JS and decrypt it on server. I use RSA for that now, but it's not the best way to do that. Commented Feb 17, 2014 at 18:52

3 Answers 3

1

If you are using RSA you have to have keys in the browser. The keys can't get to the browser unless they go over the unsecured HTTP connection. If an attacker has the keys by sniffing the HTTP connection, and the algorithm from your javascript code, you aren't protecting anything since decrypting your traffic becomes trivial.

I suggest putting an nginx proxy in front of your web server. You can configure nginx to do the TLS handshake, and you can get a Comodo SSL certificate for less than $15 a year. I've done this myself in front of a Python server and truly, that's all it cost.

Sign up to request clarification or add additional context in comments.

Comments

1

I've just decided to use http://travistidwell.com/jsencrypt/index.html in way when I store public server key on client side and private server key on server side.

JS client encrypts all messages that are send to server.

Comments

0

The best way, as mentioned by Geoff Genz, is to secure your web server with HTTPS and ensuring that your login action only accepts requests through HTTPS. Configure your angular app to make requests to the HTTPS URL of your login action and all encryption will be taken care of seamlessly. You won't have to worry about manually encrypting the data clientside and then decrypting serverside. All of this will be handled by the TLS protocol which make HTTPS work.

1 Comment

But for now our server doesn't allow for TLS, and only when we got funds we can run on secure server. For now we have to find some encryption way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.