Using Zend_Crypt_Rsa – small example of how to use it

PHPMay 05 20120 Comment

For a recent project I needed to use RSA encryption to encrypt some sensitive data that was being sent from a client to a (JSON) service. Both the client and the service are written in PHP using Zend Framework, so the obvious place to look for classes implementing this functionality is… well the Zend Framework library of course. I was happily surprised finding the class Zend_Crypt_Rsa in the Crypt folder of the Zend Framework. When I wanted to check the online documentation at http://framework.zend.com/manual/en I was less happy, because it turns out there is no documentation for this class. Luckily it’s really not that hard to use. If you check out the code of the class itself it’s pretty self explanatory. However to save someone else some time it might be useful to post the steps I took to get it working, so here we go. 1. First of all you will need to have OpenSSL installed and the openssl PHP extension loaded, because the Zend_Crypt_Rsa class is dependent on it. 2. You have to generate the private and public keys that you’re going to use for the encryption (public key) and decryption (private key). You do this using the ...

(Read more...)