note 104963 deleted from function.openssl-encrypt by danbrown

From: Date: Tue, 19 Jul 2011 15:51:43 +0000
Subject: note 104963 deleted from function.openssl-encrypt by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181702@lists.php.net to get a copy of this message
Note Submitter: ittasks at gmail dot com ---- following on biohazard dot ge at gmail dot com: for whose who do not have latest version of php installed for number of reasons here is intercompatible functions <?php function sslPrm() { return array("this_is_your_password","iv_has_to_be_16b","aes-128-cbc"); } function sslEnc($msg) { list ($pass, $iv, $method)=sslPrm(); if(function_exists('openssl_encrypt')) return urlencode(openssl_encrypt(urlencode($msg), $method, $pass, false, $iv)); else return urlencode(exec("echo \"".urlencode($msg)."\" | openssl enc -".urlencode($method)." -base64 -nosalt -K ".bin2hex($pass)." -iv ".bin2hex($iv))); } function sslDec($msg) { list ($pass, $iv, $method)=sslPrm(); if(function_exists('openssl_decrypt')) return trim(urldecode(openssl_decrypt(urldecode($msg), $method, $pass, false, $iv))); else return trim(urldecode(exec("echo \"".urldecode($msg)."\" | openssl enc -".$method." -d -base64 -nosalt -K ".bin2hex($pass)." -iv ".bin2hex($iv)))); } //example of usage: $r= sslEnc("This is encryption/decryption test!"); echo "<br>\n".$r.":".sslDec($r); ?> since the padding is defined differently in php and openssl the hashed code will be different while intercompatible (meaning decryption by both methods from either encryption method will produce same results)

« previous php.notes (#181702) next »