From e1229bfb0fd233ed70d14cc3eda54607b362bce6 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 25 Aug 2016 20:58:56 -0700 Subject: [PATCH] Graceful decryption method --- app/Helpers/Helper.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index de1cae1ca2..d92a2c9881 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -17,6 +17,8 @@ use App\Models\Component; use App\Models\Accessory; use App\Models\Consumable; use App\Models\Asset; +use Crypt; +use Illuminate\Contracts\Encryption\DecryptException; /* * To change this license header, choose License Headers in Project Properties. @@ -476,6 +478,21 @@ class Helper } + public static function gracefulDecrypt(CustomField $field, $string) { + if ($field->isFieldDecryptable($string)) { + + try { + Crypt::decrypt($string); + return Crypt::decrypt($string); + + } catch (DecryptException $e) { + return 'Error Decrypting: '.$e->getMessage(); + } + + } + return $string; + + } }