Created
March 6, 2012 22:14
-
-
Save albohlabs/1989352 to your computer and use it in GitHub Desktop.
PHP: password en- & decryption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/1289061/best-way-to-use-php-to-encrypt-and-decrypt | |
$key = 'password to (en/de)crypt'; | |
$string = ' string to be encrypted '; // note the spaces | |
# To Encrypt: | |
$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key)))); | |
# To Decrypt: | |
$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($key))), "\0"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment