@@ -89,6 +89,9 @@ class Crypt {
8989 /** @var IL10N */
9090 private $ l ;
9191
92+ /** @var string */
93+ private $ currentCipher ;
94+
9295 /** @var bool */
9396 private $ supportLegacy ;
9497
@@ -248,26 +251,40 @@ private function encrypt($plainContent, $iv, $passPhrase = '', $cipher = self::D
248251 }
249252
250253 /**
251- * return Cipher either from config.php or the default cipher defined in
254+ * return cipher either from config.php or the default cipher defined in
252255 * this class
253256 *
254257 * @return string
255258 */
256- public function getCipher () {
257- $ cipher = $ this ->config ->getSystemValue ('cipher ' , self ::DEFAULT_CIPHER );
258- if (!isset (self ::SUPPORTED_CIPHERS_AND_KEY_SIZE [$ cipher ])) {
259- $ this ->logger ->warning (
260- sprintf (
261- 'Unsupported cipher (%s) defined in config.php supported. Falling back to %s ' ,
262- $ cipher ,
263- self ::DEFAULT_CIPHER
264- ),
265- ['app ' => 'encryption ' ]
266- );
267- $ cipher = self ::DEFAULT_CIPHER ;
259+ private function getCachedCipher () {
260+ if (!isset ($ this ->currentCipher )) {
261+ // Get cipher either from config.php or the default cipher defined in this class
262+ $ cipher = $ this ->config ->getSystemValue ('cipher ' , self ::DEFAULT_CIPHER );
263+ if (!isset (self ::SUPPORTED_CIPHERS_AND_KEY_SIZE [$ cipher ])) {
264+ $ this ->logger ->warning (
265+ sprintf (
266+ 'Unsupported cipher (%s) defined in config.php supported. Falling back to %s ' ,
267+ $ cipher ,
268+ self ::DEFAULT_CIPHER
269+ ),
270+ ['app ' => 'encryption ' ]
271+ );
272+ $ cipher = self ::DEFAULT_CIPHER ;
273+ }
274+
275+ // Remember current cipher to avoid frequent lookups
276+ $ this ->currentCipher = $ cipher ;
268277 }
278+ return $ this ->currentCipher ;
279+ }
269280
270- return $ cipher ;
281+ /**
282+ * return current encryption cipher
283+ *
284+ * @return string
285+ */
286+ public function getCipher () {
287+ return $ this ->getCachedCipher ();
271288 }
272289
273290 /**
@@ -577,7 +594,7 @@ private function hasSignature($catFile, $cipher) {
577594 throw new GenericEncryptionException ('Missing Signature ' , $ this ->l ->t ('Missing Signature ' ));
578595 }
579596
580- // enforce signature for the new 'CTR' ciphers
597+ // Enforce signature for the new 'CTR' ciphers
581598 if (!$ skipSignatureCheck && $ signaturePosition === false && stripos ($ cipher , 'ctr ' ) !== false ) {
582599 throw new GenericEncryptionException ('Missing Signature ' , $ this ->l ->t ('Missing Signature ' ));
583600 }
0 commit comments