ConFoo Montreal 2017 Calling for Papers


(PHP 5 >= 5.3.0)

openssl_decryptDecrypts data


string openssl_decrypt ( string $data , string $method , string $password [, bool $raw_input = false [, string $iv = "" ]] )

Takes a raw or base64 encoded string and decrypts it using a given method and key.


Ta funkcja jest obecnie nieudokumentowana, dostępna jest jedynie lista jej argumentów.



The data.


The cipher method.


The password.


Setting to TRUE will take a raw encoded string, otherwise a base64 string is assumed for the data parameter.


A non-NULL Initialization Vector.

Zwracane wartości

The decrypted string on success lub FALSE w przypadku niepowodzenia.


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.

Rejestr zmian

Wersja Opis
5.3.3 The iv parameter was added.

Zobacz też:

add a note add a note

User Contributed Notes 3 notes

1 month ago
Parameters may seem obvius to some but not for everyone so:

- $data can be as the description says raw or base64. If no $option is set (this is, if value of 0 is passed in this parameter), data will be assumed to be base64 encoded. If parameter OPENSSL_RAW_DATA is set, it will be understood as row data.

- $password (key) is a String of [pseudo] bytes as those generated by the function openssl_random_pseudo_bytes().

- $options as (as for 2016) two possible values OPENSSL_RAW_DATA and OPENSSL_ZERO_PADDING. Setting both can be done by OPENSSL_RAW_DATA||OPENSSL_ZERO_PADDING. If no OPENSSL_ZERO_PADDING is specify, default pading of PKCS#7 will be done as it's been observe by [openssl at mailismagic dot com]'s coment in openssl_encrypt()

- $iv is as in the case of $password, a String of bytes. Its length depends on the algorithm used. May be the best way to generate an $iv is by:

= openssl_random_pseudo_bytes(openssl_cipher_iv_length('your algorithm'));// for example you algorithm = 'AES-256-CTR'
ittasks at gmail dot com
3 years ago
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();
     return urlencode(openssl_encrypt(urlencode($msg), $method, $pass, false, $iv));
     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();
     return trim(urldecode(openssl_decrypt(urldecode($msg), $method, $pass, false, $iv)));
     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);
2 years ago
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"
To Top