diff --git a/Civi/Crypto/CryptoRegistry.php b/Civi/Crypto/CryptoRegistry.php index b45927c8fcb5..0f5f2c5c9a92 100644 --- a/Civi/Crypto/CryptoRegistry.php +++ b/Civi/Crypto/CryptoRegistry.php @@ -261,8 +261,13 @@ public function findKey($keyIds) { return $this->keys[$matchKeyId]; } } - - throw new CryptoException("Failed to find key by ID or tag (" . implode(' ', $keyIds) . ")"); + \CRM_Core_Session::setStatus(ts('Failed to find key by ID or tag (%1)', [ + 1 => implode(' ', $keyIds), + ]), + '', + 'alert', + ['expires' => 0] + ); } /** @@ -294,7 +299,13 @@ public function findSuite($name) { return $this->cipherSuites[$name]; } else { - throw new CryptoException('Unknown cipher suite ' . $name); + \CRM_Core_Session::setStatus(ts('Unknown cipher suite', [ + 1 => $name, + ]), + '', + 'alert', + ['expires' => 0] + ); } } diff --git a/Civi/Crypto/CryptoToken.php b/Civi/Crypto/CryptoToken.php index afe415d844f8..036fcfed583f 100644 --- a/Civi/Crypto/CryptoToken.php +++ b/Civi/Crypto/CryptoToken.php @@ -145,6 +145,10 @@ public function decrypt($token, $keyIdOrTag = '*') { throw new CryptoException("Cannot decrypt token. Unexpected key: {$tokenData['k']}"); } + if (is_null($key) || !isset($key)) { + return $plainText; + } + /** @var \Civi\Crypto\CipherSuiteInterface $cipherSuite */ $cipherSuite = $registry->findSuite($key['suite']); $plainText = $cipherSuite->decrypt($tokenData['t'], $key);