encryption - 在 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
key应该是16个字符长度和AES-256-CBC
32个字符长度。
推荐阅读
- javascript - 如何在嵌套在 ul li 中的锚标记中添加活动类
- netbeans - netbeans - 调试器以代码 0xc0000135 退出
- java - 未处理的异常,但尝试捕获块似乎没有做我认为应该做的事情
- makefile - 使用 cygwin 在 Windows 上构建 Seafile-Client
- python - 随机森林sklearn
- amazon-web-services - 转移 AWS 促销积分
- angular - Angular 6 中的细粒度高度计算是可能的,还是我应该求助于 JQuery?
- vb.net - 在 .Net 中使用 XPath 对 XML 进行排序
- android - 数据绑定 - 访问 LiveData 中包含的各个属性
- c++ - 递归检查数字是否是完美素数c ++