note 14109 modified in ref.mcrypt by betz
| From: | betz@php.net | Date: | Sat, 15 Feb 2003 17:25:56 +0000 |
| Subject: | note 14109 modified in ref.mcrypt by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-44012@lists.php.net to get a copy of this message | ||
Mcrypt support in PHP has gone through cycles and it seems to have finally leveled off.
First, get libmcrypt-2.4.15 (well, that was the lastest as of today) and compile it. Pay no
attention to the mcrypt examples in this manual as most of them will simply cause your web server to
segfault. Here are some functions that I hope will help others with mcrypt.
$sCryptoKey = "whatever";
function
my_encrypt($sString) {
GLOBAL $sCryptoKey;
$iIV = mcrypt_create_iv (mcrypt_get_iv_size (MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
$sEncrypted = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $sCryptoKey, $sString, MCRYPT_MODE_ECB, $iIV);
return($sEncrypted);
} // End function my_encrypt
function
my_decrypt($sString) {
GLOBAL $sCryptoKey;
$iIV = mcrypt_create_iv (mcrypt_get_iv_size (MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
$sDecrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $sCryptoKey, $sString, MCRYPT_MODE_ECB, $iIV);
return(trim($sDecrypted));
} // End function my_decrypt
--was--
Mcrypt support in PHP has gone through cycles and it seems to have finally leveled off.
First, get libmcrypt-2.4.15 (well, that was the lastest as of today) and compile it. Pay no
attention to the mcrypt examples in this manual as most of them will simply cause your web server to
segfault. Here are some functions that I hope will help others with mcrypt.
PHP Manual Editor : Can you remove all the outdated comments and examples from the manual? It was
seriously confusing to get to the bottom of the problems I had starting to use mcrypt and it's
fairly straight forward now, I just think the PHP manual needs some updating in this area. Note that
it seems Zend's manual pages have been updated as that's where I finally got some working
example code.
Thanks!!!
$sCryptoKey = "whatever";
function
my_encrypt($sString) {
GLOBAL $sCryptoKey;
$iIV = mcrypt_create_iv (mcrypt_get_iv_size (MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
$sEncrypted = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $sCryptoKey, $sString, MCRYPT_MODE_ECB, $iIV);
return($sEncrypted);
} // End function my_encrypt
function
my_decrypt($sString) {
GLOBAL $sCryptoKey;
$iIV = mcrypt_create_iv (mcrypt_get_iv_size (MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
$sDecrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $sCryptoKey, $sString, MCRYPT_MODE_ECB, $iIV);
return(trim($sDecrypted));
} // End function my_decrypt
http://www.php.net/manual/en/ref.mcrypt.php