Simple, easy-to-use and effective PHP Encryption class. It's a standalone single file PHP class to use on your projects. It requires no dependencies or no framework.
You only need only one file:
Encryption.php
You can run everything from the index.php file, see the file for usage.
// Include the class file
require 'Encryption.php';
// Set a secret key
const KEY = 'secretkey';
// Message string to encode
$message = 'Hello world';
$encoded_text = Encryption::Encode($message, KEY);
//@return d1pXc2dsYVBqQ0NrSkJ1Zy85RWprUT09
$decoded_text = Encryption::Decode($encoded_text, KEY);
//@return Hello world
- This code uses
openssl
for encrypt & decrypt data. See PHP Manual for more information. - Default encryption method is
AES-256-CBC
. You can change it onEncryption.php
file at line14
&29
. Or you can enter it as thrid parameter on both static mathods.