我无法找到一个方法,我可以通过IV(初始化向量)到CRYPT facade
看起来好像它在内部实现了它。
如果它在内部实现了这一点,有什么方法可以获得用于特定加密的IV ?
$string = 'Some text to be encrypted';
$encrypted = IlluminateSupportFacadesCrypt::encrypt($string); // found NO way to pass IV here
$decrypted_string = IlluminateSupportFacadesCrypt::decrypt($encrypted);
如果您对Encrypter
进行源潜水,您可以看到encyrpt
方法是如何工作的:
public function encrypt($value, $serialize = true)
{
$iv = random_bytes(openssl_cipher_iv_length($this->cipher));
// ... rest of the method
}
是的,这是内部实现的。
有什么方法可以获得用于特定加密的IV ?
看decrypt
法:
public function decrypt($payload, $unserialize = true)
{
$payload = $this->getJsonPayload($payload);
$iv = base64_decode($payload['iv']);
// ... rest of the method
}
因此可以使用静脉注射。
不过你得自己把这个拿出来。
看看Encrypter
,看看发生了什么;vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php