PHP Encryption Class

May 28th, 20126 Comments Ā»

PS_Encrypt is a simple PHP encryption class to encrypt/decrypt data. You can use this class in my login script to encode/decode passwords. Click here to download.

Main features:

  1. Simple to implement, easy to understand and customize
  2. UsesĀ Rijndael 256 bit encryption
  3. Adds additional noise to the encoded data for more security

Usage Instructions

Include the encryption class in you application

The first step is to include the ps_encrypt.php file in your script.

Set the encryption key

Create a PS_Encrypt object and set the key with which your data will be encrypted.

Important: The key must remain the same throughout your application. You can not change the key once the data has been encrypted. If you change the encryption key, you won’t be able decrypt any data you might have encrypted previously.

Encrypt data

Decrypt data

Note: This class uses mcrypt library. Make sure that your PHP setup has mcrypt enabled otherwise this class won’t work.

« Submitting forms using PHP cURL

Categorized Under

PHP Development

About jatinder

» has written 17 posts


  1. amazon3d says:

    I’d like to use this code as the information I am going to be storing is going to be very sensitive and I want the passwords to be as protected as possible.
    I’m having issues trying to understand your code. How does it work in conjunction with your login script? Also is there away to prevent the user from logging in till an administrator has granted them access?

    • jatinder says:

      This class is not restricted to my login script. It provides generic encryption/decryption functionality and can be used in any PHP project. My login script will need to be modified a bit to be able to use this class. I will try to come up with an updated login script whenever I get some time away from work.

  2. Your sample has $encrypt->descrypt with an s in there. Your class uses decrypt so errors were getting thrown. Works great when I fixed that. Thanks!

  3. Hi, First of all let me thank for your great work with this and other scripts.

    I’m having a problem in the decrypt process.

    I keep getting this Warning:

    Warning: mcrypt_decrypt() [function.mcrypt-decrypt]: The IV parameter must be as long as the blocksize

    Can you give me some help with this?

    Best Regards