I am currently building a system (PHP Web Application Framework) that creates an RSA Key Pair for a user to allow other users to send secure information from one to another. The public key is unencrypted (as expected) and the private key is encrypted with the users password. As the initial RSA generation process is quite computationally expensive (generation of large primes), I am using two methods to make the primes.

The first is a java applet that runs on the clients browser, creates the primes and keys, secures the private key with the password, and sends it back to the system where it is stored and used later.

The second is to use an application (running on the web server as a cron or on another server that can access and update the app) which will do the same as the applet. However, I am still not sure about how to secure the private key so it is only accessible to the user, and it can't be accessed by anyone else.

Sadly, this is where I am hitting a road block. I am unsure of how to secure the data (either generated on the web server or by another server), so it (or the users password) is not directly or indirectly available to any hackers, even if they have access to the entire file system and database on the server. Does anyone have any suggestions on how something like this could be achieved?

1 Answer 1


I am not sure of what you are trying to achieve here. If you are trying to secure user data, so that only the receiver of the message has access to it, then a solution would be:

  • Generate the certificate on the client, using the applet and protect the private key using a password (the user password or another password)
  • Send the public key to the server so that it is available when someone wants to send an encrypted message.
  • The private key should not leave the computer of the client. The obvious problem here is that if the user uses another computer to access your application he would need to copy the certificate there. You can solve this problem by using smartcards or USB tokens and store the certificates there. In this way, you would only need the token's password to access the private key.

If you also have some sort of admin functionality and you have an user that should be able to decrypt everything, then things get a little bit more complicated. You may have an admin certificate and after the applet generates the keypair, encrypt it using the admin's public key and send it to the server, where you should store it in an encrypted form.

At least the admin should have an USB token with his certificate, so that even if an attacker gains access to your server, he would not have access to any of the private keys that could decrypt messages.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .