Reputation: 2687
I am unable to find a method in which I can pass IV(Initialization Vector) to CRYPT facade of Laravel framework in PHP
It appears as if it somehow internally implements it.
If it internally implements this, any way I can get the IV used for a particular encryption ?
$string = 'Some text to be encrypted';
$encrypted = \Illuminate\Support\Facades\Crypt::encrypt($string); // found NO way to pass IV here
$decrypted_string = \Illuminate\Support\Facades\Crypt::decrypt($encrypted);
Upvotes: 0
Views: 713
Reputation: 16339
If you source dive the Encrypter
you can see how the encyrpt
method works:
public function encrypt($value, $serialize = true)
{
$iv = random_bytes(openssl_cipher_iv_length($this->cipher));
// ... rest of the method
}
So yes, this is internally implemented.
any way I can get the IV used for a particular encryption ?
Looking at the decrypt
method:
public function decrypt($payload, $unserialize = true)
{
$payload = $this->getJsonPayload($payload);
$iv = base64_decode($payload['iv']);
// ... rest of the method
}
So it is possible to get the IV used.
Although you'll have to get this out yourself.
Take a look at the Encrypter
to see what's going on; vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php
Upvotes: 2