'openssl_encrypt does not return anything

function encrypt($text,$key){

    $method = 'AES-256-CBC';
    $size = openssl_cipher_iv_length($method);
    $iv = substr($key, 0, $size);
    $openssl = openssl_encrypt($text, $method, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
    return base64_encode($openssl);

}

This method does not return anything, I am just trying to write a reliable encryption function using openssl.

php


Solution 1:[1]

Correct syntax is

$openssl = openssl_encrypt($text, $method, $key, OPENSSL_RAW_DATA || OPENSSL_ZERO_PADDING, $iv);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aman Gupta