[wd_asp elements=’search’ ratio=’100%’ id=1]

Password Encryption using mcrypt

27th January 2014

Php - Strings

php codehaven

The bare bones of encryption, remember to encrypt incoming and compare against the encrypted version.

You can include the salt in another file, if you like.

$salt = 'myencryptionkey';
$string = 'password';

$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($salt), $string, MCRYPT_MODE_CBC, md5(md5($salt))));
$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($salt), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($salt))), "\0");

echo $encrypted;
echo $decrypted;