note 88687 deleted from function.mcrypt-encrypt by danbrown

From: Date: Wed, 06 May 2009 21:57:34 +0000
Subject: note 88687 deleted from function.mcrypt-encrypt by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154291@lists.php.net to get a copy of this message
Note Submitter: Kai Sellgren ---- bantam (below) has written a bad example. He was base64 decoding even though he never base64 encoded. In addition to that, the trimming is not effective and the cipher block mode is not secure. Here is a very good approach to encrypt / decrypt data. <?php $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $iv = mcrypt_create_iv($iv_size,MCRYPT_RAND); $key = "my secret key"; $text = "I discovered a way to crack into the White House."; // Just kidding :P $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256,$key,$text, MCRYPT_MODE_CBC,$iv); $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key,$crypttext, MCRYPT_MODE_CBC,$iv); echo rtrim($decrypttext,"\0"); ?>

« previous php.notes (#154291) next »