Encrypting data with PHP using the phpSec library
Encryption is a easy and secure way of protection your data. phpSec implements symmetric encryption using the mcrypt library, end is extremely easy to use.
$data = 'This is some extremely secret information.';
$encrypted = phpsecCrypt::encrypt($data, 'secret key');
The above code will encrypt the $data string, using the "secret key". Note that you can also pass arrays to encrypt.
$encrypted will contain something like:
{
"cdata":"qLUmR1giVp01tVslDexNn4wKSFGTOD+v2PV1MuPs\/eL26IuUvM8+jQ==",
"hash":"c9785eb8fb5739a139e83f2c2bc52dd4cac6bf1f3c7c0691a2499474d9ef3cd5",
"algo":"blowfish",
"mode":"cbc",
"iv":"lWLWME\/dQP4="
}
To decrypt the data again you need the secret key:
$data = phpsecCrypt::decrypt($encrypted, 'secret key');
So there you have it. Simple as pie. To download phpSec go to the GitHub download page, and to get started using it take a look at the getting started guide.
