Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 拉威尔5.3及;Crypt-无效负载_Php_Encryption_Laravel 5.2 - Fatal编程技术网

Php 拉威尔5.3及;Crypt-无效负载

Php 拉威尔5.3及;Crypt-无效负载,php,encryption,laravel-5.2,Php,Encryption,Laravel 5.2,我有一个我在Laravel 5.23中写的应用程序。在它中,我在将某些敏感用户数据存储到表中之前,使用以下方法对其进行加密: 'Crypt' => Illuminate\Support\Facades\Crypt::class, 该字段的迁移是: $table->string('field_account_name')->nullable(); 我在课堂上设置了变异子来实现这一点: public function getFieldAccountNameClearAt

我有一个我在Laravel 5.23中写的应用程序。在它中,我在将某些敏感用户数据存储到表中之前,使用以下方法对其进行加密:

'Crypt'     => Illuminate\Support\Facades\Crypt::class,
该字段的迁移是:

$table->string('field_account_name')->nullable();
我在课堂上设置了变异子来实现这一点:

public function getFieldAccountNameClearAttribute($value)
{
    if ($this->field_account_name) {
        try {
            return Crypt::decrypt($this->field_account_name);
        } catch (DecryptException $e) {
            return 'INVALID';
        }
    } else {
        return $this->field_account_name;
    }
}

这已经完美地工作了很长一段时间,但一个用户在一周前放弃了他们的魔法,并触发:

Exception 'ErrorException' with message 'The payload is invalid
我通过在字段中放置特殊字符(如
)作为带空格的长字符串的一部分,成功地复制了这个问题

日期已加密并存储,但检索时失败

为了避免这种情况,我是否应该从前端的加密中排除一些字符?我找不到答案


或者,该字段应该是
text
而不是string?

这个问题可能与您试图加密的数据量以及它在数据库中的存储方式有关。如果加密文本超过255个字符,则在将其添加到数据库时将被截断,这意味着无法对其进行解密

您应该将现有迁移更新为:

$table->text('field_account_name')->nullable();
或者在新迁移中使用以下内容:

$table->text('field_account_name')->nullable()->change();

这个问题可能与您试图加密的数据量以及它在数据库中的存储方式有关。如果加密文本超过255个字符,则在将其添加到数据库时将被截断,这意味着无法对其进行解密

您应该将现有迁移更新为:

$table->text('field_account_name')->nullable();
或者在新迁移中使用以下内容:

$table->text('field_account_name')->nullable()->change();

您应该使用
text
而不是
varchar
您应该使用
text
而不是
varchar
谢谢。我将字段更改为
TEXT
,现在一切正常。谢谢。我将字段更改为
TEXT
,现在一切正常。