在Laravel中加密时如何为不同的用户使用不同的密钥?
How to use different keys for different users when encrypt in Laravel?
我尝试加密 Laravel5.7
中的文件
$encryptedContent = encrypt($fileContent);
用于加密文件。
$decryptedContent = base64_encode(decrypt($encryptedContent));
解密成功。
我的问题是我需要为不同的用户使用不同的密钥来加密和解密文件。
我尝试了以下方法。
$crypt = new \Illuminate\Encryption\Encrypter($newkey);
$encryptedContent = $crypt->encrypt($fileContent);
但它给出了以下错误。
The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths
谁能帮帮我?
谢谢。
问题出在密钥长度上。
如果我们使用 AES-128-CBC
键应该是 16 个字符长度和 AES-256-CBC
32 个字符长度。
我尝试加密 Laravel5.7
中的文件$encryptedContent = encrypt($fileContent);
用于加密文件。
$decryptedContent = base64_encode(decrypt($encryptedContent));
解密成功。
我的问题是我需要为不同的用户使用不同的密钥来加密和解密文件。 我尝试了以下方法。
$crypt = new \Illuminate\Encryption\Encrypter($newkey);
$encryptedContent = $crypt->encrypt($fileContent);
但它给出了以下错误。
The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths
谁能帮帮我? 谢谢。
问题出在密钥长度上。
如果我们使用 AES-128-CBC
键应该是 16 个字符长度和 AES-256-CBC
32 个字符长度。