note 104963 added to function.openssl-encrypt
| From: | ittasks at gmail dot com | Date: | Tue, 19 Jul 2011 08:02:08 +0000 |
| Subject: | note 104963 added to function.openssl-encrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181684@lists.php.net to get a copy of this message | ||
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)
----
Server IP: 69.147.83.197
Probable Submitter: 173.35.192.189
----
Manual Page -- http://www.php.net/manual/en/function.openssl-encrypt.php
Edit -- https://master.php.net/note/edit/104963
Del: integrated -- https://master.php.net/note/delete/104963/integrated
Del: useless -- https://master.php.net/note/delete/104963/useless
Del: bad code -- https://master.php.net/note/delete/104963/bad+code
Del: spam -- https://master.php.net/note/delete/104963/spam
Del: non-english -- https://master.php.net/note/delete/104963/non-english
Del: in docs -- https://master.php.net/note/delete/104963/in+docs
Del: other reasons-- https://master.php.net/note/delete/104963
Reject -- https://master.php.net/note/reject/104963
Search -- https://master.php.net/manage/user-notes.php