如何在 PHP 中的 Laravel 为 CRYPT facade 传递 IV
How to pass IV for CRYPT facade at Laravel in PHP
我找不到可以将 IV(初始化向量)传递给 CRYPT facade of 的方法]Laravel PHP
中的框架
它似乎以某种方式在内部实现了它。
如果它在内部实现了这个,我可以通过任何方式获得用于特定加密的 IV?
$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);
如果您深入了解 Encrypter
,您可以看到 encyrpt
方法的工作原理:
public function encrypt($value, $serialize = true)
{
$iv = random_bytes(openssl_cipher_iv_length($this->cipher));
// ... rest of the method
}
所以是的,这是内部实现的。
any way I can get the IV used for a particular encryption ?
查看decrypt
方法:
public function decrypt($payload, $unserialize = true)
{
$payload = $this->getJsonPayload($payload);
$iv = base64_decode($payload['iv']);
// ... rest of the method
}
因此可以使用IV。
虽然你必须自己解决这个问题。
看看 Encrypter
看看发生了什么; vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php
我找不到可以将 IV(初始化向量)传递给 CRYPT facade of 的方法]Laravel PHP
中的框架它似乎以某种方式在内部实现了它。
如果它在内部实现了这个,我可以通过任何方式获得用于特定加密的 IV?
$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);
如果您深入了解 Encrypter
,您可以看到 encyrpt
方法的工作原理:
public function encrypt($value, $serialize = true)
{
$iv = random_bytes(openssl_cipher_iv_length($this->cipher));
// ... rest of the method
}
所以是的,这是内部实现的。
any way I can get the IV used for a particular encryption ?
查看decrypt
方法:
public function decrypt($payload, $unserialize = true)
{
$payload = $this->getJsonPayload($payload);
$iv = base64_decode($payload['iv']);
// ... rest of the method
}
因此可以使用IV。
虽然你必须自己解决这个问题。
看看 Encrypter
看看发生了什么; vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php