Dally's avatar
Level 1

opensll_decrypt & aes-256-gcm doesn't seem to work

Hi guys, I can't seem to get opensll_decrypt working with aes-256-gcm. I'm getting no error but no response either.

Here's the code:

$key_from_configuration = '30053D479609E8D9EF51B2413AD9AE973F9C3075A4ED504122D2FA1842E23FCC';
$headers = apache_request_headers();

foreach ($headers as $header => $value) {
    if($header == 'X-Initialization-Vector') {
        $iv_from_http_header = $value;
    }
    if($header == 'X-Authentication-Tag') {
        $auth_tag_from_http_header = $value;
    }
}
$http_body = substr(substr($request, strpos($request, 'Body":"') + 7), 0, -2);

$key = hex2bin($key_from_configuration);
$iv = hex2bin($iv_from_http_header);
$auth_tag = hex2bin($auth_tag_from_http_header);
$cipher_text = hex2bin($http_body);

$result = openssl_decrypt($cipher_text, "aes-256-gcm", $key, 0, $iv, $auth_tag);

Storage::put('test.txt', $auth_tag_from_http_header);
Storage::put('test-body.txt',  $result);

The variables are definetly populated as I've outputted them to a .txt file.

As a workaround I've used the php-aes-gcm package which is working fine but as opensll supports aes-256-gcm in PHP 7.2, why doesn't this work in Laravel?

0 likes
0 replies

Please or to participate in this conversation.