gpt4 book ai didi

php - future 我们可以依赖 Laravel 加密吗?

转载 作者:行者123 更新时间:2023-11-29 10:40:08 25 4
gpt4 key购买 nike

我们正在构建需要在数据库中存储加密数据的应用程序,我们不使用 MySql AES_ENCRYPT 和 AES_DECRYPT,而是使用 Laravel 的内置加密和解密函数。

它是否会面向 future ,因为我们不想丢失 future 更新的数据。

最佳答案

首先,没有什么是真正“面向 future 的”。事实上,我们正处于当前加密技术被量子计算淘汰的边缘,使得所有当前加密方法都无法适应 future 。

泰勒有在可预见的将来改变它的计划吗?也许,也许不是,但唯一真正了解的方法就是直接问他。他在 Twitter 和其他场所非常活跃,因此对于企业主来说,他非常平易近人。他总体上也是一个很好的人,所以不要害怕联系他。

But let's take a look at the code:

public function encrypt($value, $serialize = true)
{
$iv = random_bytes(16);
// First we will encrypt the value using OpenSSL. After this is encrypted we
// will proceed to calculating a MAC for the encrypted value so that this
// value can be verified later as not having been changed by the users.
$value = \openssl_encrypt(
$serialize ? serialize($value) : $value,
$this->cipher, $this->key, 0, $iv
);
if ($value === false) {
throw new EncryptException('Could not encrypt the data.');
}
// Once we get the encrypted value we'll go ahead and base64_encode the input
// vector and create the MAC for the encrypted value so we can then verify
// its authenticity. Then, we'll JSON the data into the "payload" array.
$mac = $this->hash($iv = base64_encode($iv), $value);
$json = json_encode(compact('iv', 'value', 'mac'));
if (! is_string($json)) {
throw new EncryptException('Could not encrypt the data.');
}
return base64_encode($json);
}

这是存储库中 master 的主要 encrypt() 函数,从它的外观来看,如果不完全重写它,它不太可能改变太多。虽然 Laravel 并不真正遵循 SemVer 版本控制规范,但它通常遵循内部一致的版本控制方案,因此最有可能更改的时间是整数和第一位小数更改(即 - 5.4 到 5.5 或 5.5)至 6.0)。

但是,值得注意的是,它实际上是通过契约和服务提供者模式访问的(因此该类唯一一次实际直接引用是在其关联的 ServiceProvider 类中)。这意味着您现在可以使用这个版本,如果将来引入重大更改,您可以将此版本复制到您自己的加密类中,将 config/app.php 中的引用替换为 Illuminate\Encryption\EncryptionServiceProvider 到您的新加密服务提供商,您现在已保留该方法并可以在整个应用程序中使用它,而无需对应用程序进行任何其他更改。

顺便说一句,如果您发现确实需要通过使用旧系统的解密方法来解密所有内容来更改算法(例如,如果您的原始算法不安全),您也可以考虑编写一个“加密转换器” ,然后用新系统重新加密并再次存储。然后应用程序将继续使用新算法。

关于php - future 我们可以依赖 Laravel 加密吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45637167/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com