©
本文档使用 PHP中文网手册 发布
(PHP 5 >= 5.3.0)
openssl_decrypt — Decrypts data
$data
, string $method
, string $password
[, int $options
= 0
[, string $iv
= ""
]] )Takes a raw or base64 encoded string and decrypts it using a given method and key.
本函数还未编写文档,仅有参数列表。
data
The data.
method
The cipher method.
password
The password.
options
options
can be one of
OPENSSL_RAW_DATA
,
OPENSSL_ZERO_PADDING
.
iv
A non-NULL Initialization Vector.
The decrypted string on success 或者在失败时返回 FALSE
.
Emits an E_WARNING
level error if an unknown cipher algorithm
is passed via the method
parameter.
Emits an E_WARNING
level error if an empty value is passed
in via the iv
parameter.
版本 | 说明 |
---|---|
5.3.3 |
The iv parameter was added.
|
5.4.0 |
The raw_output was changed to options .
|
[#1] Anonymous [2014-04-19 16:33:24]
If your using windows os, do not use the text inside the "file previewer" pane, as this is a truncated version of the actual encrypted string.
Instead, you need to open the file directly and use the contents there.
The error message I had been getting was:
"error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length"
[#2] ittasks at gmail dot com [2013-04-03 00:02:55]
in case that hosting do not provide openssl_encrypt decrypt functions - it could be mimiced via commad prompt executions
this functions will check is if openssl is installed and try to use it by default
function sslPrm()
{
return array("your_password","IV (optional)","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);