Php - Openssl_decrypt Error : Wrong Final Block Length (aes 256 Cbc Mode Encryption/decryption)
This is my code : function decrypt($code) { $key = '3552ef55ecdf04324..'; // 64 bytes length $iv = 'd20818af907b59c3b15d258dd3969770'; // 32 bytes length $key = hash
Solution 1:
I solve the problem. The fact is that i am URLEncoding params on Android side, and then URLDecoding them with my PHP script.
Unfortunately, the URL decoding of a '+' is a whitespace in Android but in ios it is correct ('+').
So on PHP side i substituted the whitespace character with '+' before Decoding. And i remove the base64_decode function.
Updated code:
function decrypt($code)
{
$key = '3552ef55ecdf04324d0fe72343...';
$iv = 'd20818af907b59c3b15d258dd3969770';
$key = hash("sha256", $key, true);
$iv = md5($iv, true);
if (preg_match('/\s/', trim($code))) {
$code = str_replace(' ', '+', trim($code));
}
$output = openssl_decrypt($code, 'aes-256-cbc', $key, 0, $iv);
return$output;
}
Post a Comment for "Php - Openssl_decrypt Error : Wrong Final Block Length (aes 256 Cbc Mode Encryption/decryption)"