@@ -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
@@ -104,6 +107,23 @@ public function __construct(ILogger $logger, IUserSession $userSession, IConfig
104107 $ this ->config = $ config ;
105108 $ this ->l = $ l ;
106109 $ this ->supportLegacy = $ this ->config ->getSystemValueBool ('encryption.legacy_format_support ' , false );
110+
111+ // Get cipher either from config.php or the default cipher defined in this class
112+ $ cipher = $ config ->getSystemValue ('cipher ' , self ::DEFAULT_CIPHER );
113+ if (!isset (self ::SUPPORTED_CIPHERS_AND_KEY_SIZE [$ cipher ])) {
114+ $ logger ->warning (
115+ sprintf (
116+ 'Unsupported cipher (%s) defined in config.php supported. Falling back to %s ' ,
117+ $ cipher ,
118+ self ::DEFAULT_CIPHER
119+ ),
120+ ['app ' => 'encryption ' ]
121+ );
122+ $ cipher = self ::DEFAULT_CIPHER ;
123+ }
124+
125+ // Remember current cipher to avoid frequent lookups
126+ $ this ->currentCipher = $ cipher ;
107127 }
108128
109129 /**
@@ -254,20 +274,7 @@ private function encrypt($plainContent, $iv, $passPhrase = '', $cipher = self::D
254274 * @return string
255275 */
256276 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 ;
268- }
269-
270- return $ cipher ;
277+ return $ this ->currentCipher ;
271278 }
272279
273280 /**
@@ -577,7 +584,7 @@ private function hasSignature($catFile, $cipher) {
577584 throw new GenericEncryptionException ('Missing Signature ' , $ this ->l ->t ('Missing Signature ' ));
578585 }
579586
580- // enforce signature for the new 'CTR' ciphers
587+ // Enforce signature for the new 'CTR' ciphers
581588 if (!$ skipSignatureCheck && $ signaturePosition === false && stripos ($ cipher , 'ctr ' ) !== false ) {
582589 throw new GenericEncryptionException ('Missing Signature ' , $ this ->l ->t ('Missing Signature ' ));
583590 }
0 commit comments