Using OPENSSL_RAW_DATA parameter in openssl_decrypt with php 5.3

My company implements Vme checkout on our website. Visa provided us with a php helper function file to decrypt the data, but one of them uses openssl_decrypt with the OPENSSL_RAW_DATA parameter, which became available only in PHP 5.4.something.

 return openssl_decrypt($data, 'aes-256-cbc', hashKey($key), OPENSSL_RAW_DATA, $iv); 

We are running PHP 5.3, and there is no way to upgrade. How can I change this function so that it still performs what it was intended without this global parameter?

+8
php encryption php-openssl
source share
1 answer

Just pass (integer) 1 that the value of the constant is OPENSSL_RAW_DATA :

 return openssl_decrypt($data, 'aes-256-cbc', hashKey($key), 1, $iv); 

Prior to PHP 5.4, this was a boolean parameter called "raw_data", so you could also pass a boolean TRUE, but there is an advantage to using an integer - it is compatible with the former.

In PHP 5.3, int (1) is implicitly cast to a logical TRUE, and in 5.4+ you pass the value of the real flag.

+12
source share

All Articles