我正在尝试迁移以下我用来将DB中的某些列加密到本机Laravel 9加密铸件。
我得到的问题是,尽管它适合新值,但对于现有值,我得到了一些额外的值。
因此,解密后没有获得清洁价值:
Harry Potter
我将得到以下内容:
s:23:"Harry Potter";
我不确定最好的方法是什么?我正在考虑循环浏览所有值并运用一些正则等级,但是这太疯狂了,到目前为止,我已经有很多列和价值。
I'm trying to migrate the following trait that I used to encrypt certain columns in my DB to the native Laravel 9 encrypted cast.
The problem I'm getting is that, although it works great for new values, for existing values I'm getting some extra values.
So instead of getting a clean value after decryption:
Harry Potter
I'm getting the following:
s:23:"Harry Potter";
And I'm not sure what's the best way to proceed? I was thinking about looping through all the values and applying some RegEx, but it's crazy, I have a lot of columns and values by now.
发布评论
评论(3)
假设您尚未使用两种不同的方法具有混合的加密值:
一种解决方案可能是评论模型中的可加密属性(自定义特征之一),然后编写代码,以重新保存所有具有加密值的模型(这应该保存列解密)。
在这一点上,您可以从项目中删除自定义特征,并在模型中添加Laravel 9加密铸件,并编写代码以重新释放所有内容。
Assuming you don't already have mixed encrypted values with the two different methods :
One solution could be to comment the encryptable attribute in your models(the one of the custom trait) then write code that re-saves all your models that have encrypted values (this should save the columns decrypted).
At this point you'd remove the custom trait from your project and add the Laravel 9 encrypted cast in your models and write code to re-save everything.
您应该运行迁移以加密值。例如:
You should run a migration to encrypt the values. For example:
我猜想当您尝试迁移到本机加密铸件时,它使用了
genterpt()
助手方法。在最新的。尝试与他们俩一起测试,以查看在您的情况下正在使用的。可能与序列化选项不匹配。
I am guessing when you tried to migrate to the native encrypted cast, it used the
encrypt()
helper method. In the latest versions, the method used has been updated toCrypt::encryptString
.Try testing with both of them to see which is being used in your case. There might be a mismatch with the serialization options.