Created
May 10, 2011 05:52
-
-
Save tracend/963967 to your computer and use it in GitHub Desktop.
PHP: Encryption / decryption of passwords
This file contains hidden or 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
<?php | |
function encryptPassword($value){ | |
if(!$value){return false;} | |
$text = $value; | |
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); | |
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); | |
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SECRET_KEY, $text, MCRYPT_MODE_ECB, $iv); | |
return trim(base64_encode($crypttext)); //encode for cookie | |
} | |
function decryptPassword($value){ | |
if(!$value){return false;} | |
$crypttext = base64_decode($value); //decode cookie | |
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); | |
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); | |
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SECRET_KEY, $crypttext, MCRYPT_MODE_ECB, $iv); | |
return trim($decrypttext); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment