Encryption
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==",
Effective key size
Creating keys for use with encryption is not as easy as the guys writing the PHP manual thinks it is. The following example on the mcrypt_module_open() page shows just that. To generate a key they use the following example:
/* Create key */
$key = substr(md5('very secret key'), 0, $ks);
Already in 2006 "Mon" comments:
In the text example:
$key = substr(md5('very secret key'), 0, $ks);
Builds a key of $ks/2 effective bytes.
PHP hash tool
I often find myself in the need to create a md5/sha256 hash for various reasons. Most of the time I use Google to find a javascript tool that i can use. This is fine, but a bit inconvenient, so i decided to create a little script that can create all sorts of hashes from a string.
