Laravel解密问题

时间:2018-03-29 04:35:43

标签: laravel encryption laravel-5

我在解密一些我刚刚尝试过加密的值时遇到了问题。我已经生成了密钥as stated in the docs

我已经使用我的控制器导入了我的值,如下所示:

public function importEquipment (Request $request)
                                                                {
    if($request->file('imported-file'))
      {
                $path = $request->file('imported-file')->getRealPath();
                $data = Excel::load($path, function($reader) {
                    })->get();
                    if(!empty($data) && $data->count()){
                        foreach ($data as $key => $value) {
                            Equipment::create([
                              'active' => $value->active,
                              'licensePlate' => encrypt($value->licensePlate),
                              'notes' => $value->notes,
                              'purchaseDate' => $value->purchaseDate,
                              'titleNumber' => encrypt($value->titleNumber),
                              'tires' => $value->tires,
                              'unit_type' => $value->unit_type,
                              'unitTypeLabel' => $value->unitTypeLabel,
                              'unit_id' => $value->unit_id,
                              'VIN' => encrypt($value->VIN),
                              'year' => $value->year,
                              'customerID' => 1,
                            ]);
                        }
                    }
                }
        Session::flash('flash_message','Equipment successfully imported!');
        return back();
    }   

正如您所看到的,我选择加密有三个值,看起来它们在longtext字段中成功生成。

但是,当我通过我的网站访问设备的“索引”时,当我打印以下eyJpdiI6Im5IUnFkdEFNS3JDV1RQajdyQVZMMEE9PSIsInZhbHVlIjoiYWZGYXU0Y1dTcG5aOEFWbHI0amR6QT09IiwibWFjIjoiNzkwNWQ1YzYwOGJjZjdmMTc1Zjg0ZTVmNWZkMjViY2M5YjA5OTM4MGJhYjE1YjNkYTQ5ZjI0MDg2M2YxM2EyZiJ9时,我会得到类似{{$equipment->VIN}}的内容,但是当我{{decrypt($equipment->VIN}}时没有出现。

我是否在解密时遇到了问题?在@foreach环境中进行解密是否有适当的解决方法?

1 个答案:

答案 0 :(得分:3)

我认为这会对你有帮助......

尝试

 Crypt::decrypt($equipment->VIN));

 Crypt::decrypt($value->VIN));

了解更多信息请访问Decrypting A Value