I am developing an app in Laravel Framework 5.7.13.
I have a class called
<?php
namespace App\Library;
class Crypto{
private $cipher;
private $cstrong;
private $keylen;
private $key;
public function __Crypto(){
$this->cipher= Config::get('cipher');
$this->cstrong = true;
$this->keylen = 5;
$this->key = bin2hex(openssl_random_pseudo_bytes($keylen, $cstrong));
}
public function opensslEncrypt($value){
$ivlen = openssl_cipher_iv_length($this->cipher);
$iv = openssl_random_pseudo_bytes($ivlen);
$ciphertext_raw = openssl_encrypt($value, $this->cipher, $this->key, $options=OPENSSL_RAW_DATA, $iv);
$hmac = hash_hmac('sha256', $ciphertext_raw, $this->key, $as_binary=true);
$ciphertext = base64_encode( $iv.$hmac.$ciphertext_raw );
return $ciphertext ;
}
}
Now in my controller I did:
$crypto = new Crypto();
$encryptedValue = $crypto->opensslEncrypt($orderId);
In my Config\app.php
'cipher' => 'AES-256-CBC'
But when I run my app, I get
ErrorException (E_WARNING) openssl_cipher_iv_length(): Unknown cipher algorithm
How to resolve this?
I tried to comment the cipher line in the Config\app.php, but then it gave some other errors.
Please help...