Re: mcrypt_encrypt help needed
| From: | Rick Dwyer | Date: | Wed, 30 Nov 2011 21:57:06 +0000 |
| Subject: | Re: mcrypt_encrypt help needed | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-315905@lists.php.net to get a copy of this message | ||
My decrypt is below:
$myval=$_GET["myval"];
// let the encryption begin
define('SALT', 'myvalueforsalthere');
function decrypt($text)
{
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SALT, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));} echo decrypt($myval); --Rick On Nov 30, 2011, at 4:14 PM, Adam Richardson wrote:
On Wed, Nov 30, 2011 at 3:57 PM, Rick Dwyer <rpdwyer@earthlink.net> wrote:Hello all. I am using the following function to encrypt a string: define('SALT', 'myvalueforsalthere'); function encrypt($text) { return trim(base64_encode(mcrypt_**encrypt(MCRYPT_RIJNDAEL_256, SALT, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_**iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)))); } and then: $myval="hello"; $mayval= encrypt($myval); echo decrypt($myval); returns "hello".... great. But when my input string is more complicated I get unprintable characters out of the decyrpt side: $myval="var1=1&var2=2&var3=3"; The above when decrypted will spit out a string of unprintable characters. Is encrypt/decrypt choking on the "=" sign? I tried: $myval=htmlentities($myval); But it did not work. Any help is appreciated. Thanks, --RickHi Rick, Can you show us the decrypt function, too (even though it should be just the reverse order of operations using a decrypt function, I'd just like to double check it before commenting.) By the way, I wouldn't recommend using ECB mode unless you have a special circumstance: http://www.quora.com/Is-AES-ECB-mode-useful-for-anything Adam (Sorry for the duplicate, Rick, I forgot to reply all the first time.) --Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com