diff --git a/core/simplecrypt.class.inc.php b/core/simplecrypt.class.inc.php index b49d0c2d1..0be60cf20 100644 --- a/core/simplecrypt.class.inc.php +++ b/core/simplecrypt.class.inc.php @@ -130,7 +130,15 @@ class SimpleCrypt */ function Decrypt($key, $string) { - return $this->oEngine->Decrypt($key,$string); + try{ + return $this->oEngine->Decrypt($key,$string); + } catch(\Exception $e){ + if (strlen($string)==0){ + IssueLog::Warning("Cannot decrypt empty/null value", null, ['msg' => $e->getMessage(), 'stack' => $e->getTraceAsString()]); + return $string; + } + throw $e; + } } /** @@ -422,4 +430,4 @@ class SimpleCryptOpenSSLMcryptCompatibilityEngine implements CryptEngine return trim($plaintext); } -} +} \ No newline at end of file diff --git a/tests/php-unit-tests/unitary-tests/core/SympleCryptTest.php b/tests/php-unit-tests/unitary-tests/core/SympleCryptTest.php new file mode 100644 index 000000000..e38f1d745 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/core/SympleCryptTest.php @@ -0,0 +1,36 @@ +assertEquals(null, $oSimpleCrypt->Decrypt("dd", null)); + } + + public function testDecryptWithEmptyValue() + { + $oSimpleCrypt = new \SimpleCrypt("Sodium"); + $this->assertEquals('', $oSimpleCrypt->Decrypt("dd", "")); + } + + public function testDecrypNonDecryptableValue() + { + $this->expectException(SodiumException::class); + $oSimpleCrypt = new \SimpleCrypt("Sodium"); + $this->assertEquals('', $oSimpleCrypt->Decrypt("dd", "gabuzomeu")); + } + +}