- Simple to implement, easy to understand and customize
- Uses Rijndael 256 bit encryption
- Adds additional noise to the encoded data for more security
Include the encryption class in you application
The first step is to include the ps_encrypt.php file in your script.
//Include the PS_Encrypt class require_once('ps_encrypt.php');
Set the encryption key
Create a PS_Encrypt object and set the key with which your data will be encrypted.
$encrypt = new PS_Encrypt(); //Set the encryption key. The key must remain same for your application. $encrypt->setKey('q%6WXdXnv&%g');
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.
$encrypted_data = $encrypt->encrypt('secret_password'); //You can now store the $encrypted_data to your database
$decrypted_data = $encrypt->decrypt($encrypted_data); echo $decrypted_data; //Will output "secret_password"
Note: This class uses mcrypt library. Make sure that your PHP setup has mcrypt enabled otherwise this class won’t work.