Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for an asymmetric encryption library for php that can generate keys, hand out public keys and decrypt incoming messages with the corresponding private key. However, I'm a novice in the field of encryption and while googling for a usable library, I always come across all these functions that take tons of arguments of which I have no idea what they are for and how they work.

What I basically need is 3 functions like this :

  • list($public_key, $private_key) = generate_random_keys(); //Generate a pair of keys that I put in a database. Then hand out the public key to a certain user.

  • $encrypted_message = encrypt($message, $public_key); //Encrypt a message to a user with the public key associated with that user.

  • $decrypted_message = decrypt($encrypted_message, $private_key); //Decrypt an incoming message from a user with the private key associated with that user.

Does anyone know a simple library for that, that doesn't need all kinds of extra parameters that need to be in all kinds of formats that aren't clear to people who have no experience in these things?

share|improve this question
What's wrong with openssl bindings ? they seem to provide what you want... – b0fh Aug 5 '10 at 15:08

Check out OpenSSL and GnuPG for PHP

(I can't post more than one hyperlink so search for GnuPG on the PHP site to get more info)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.