@@ -119,16 +119,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
119119 $ readConnection = Mage::getSingleton ('core/resource ' )->getConnection ('core_read ' );
120120 $ writeConnection = Mage::getSingleton ('core/resource ' )->getConnection ('core_write ' );
121121
122- $ this ->recryptAdminUserTable ($ output , $ readConnection , $ writeConnection );
123- $ this ->recryptCoreConfigDataTable ($ output , $ readConnection , $ writeConnection );
124- Mage::app ()->getCache ()->clean ('config ' );
125-
126- Mage::dispatchEvent ('encryption_key_regenerated ' , [
127- 'output ' => $ output ,
128- 'encrypt_callback ' => [$ this , 'encrypt ' ],
129- 'decrypt_callback ' => [$ this , 'decrypt ' ],
130- ]);
131- Mage::app ()->getCache ()->clean ('config ' );
122+ if ($ this ->isOldEncryptionKeyM1 && !function_exists ('mcrypt_module_open ' )) {
123+ $ output ->writeln ('<comment>Skipping re-encryption of existing data (M1 key without mcrypt support).</comment> ' );
124+ $ output ->writeln ('<comment>Old encrypted data will no longer be decryptable. New data will use the new key.</comment> ' );
125+ } else {
126+ $ this ->recryptAdminUserTable ($ output , $ readConnection , $ writeConnection );
127+ $ this ->recryptCoreConfigDataTable ($ output , $ readConnection , $ writeConnection );
128+ Mage::app ()->getCache ()->clean ('config ' );
129+
130+ Mage::dispatchEvent ('encryption_key_regenerated ' , [
131+ 'output ' => $ output ,
132+ 'encrypt_callback ' => [$ this , 'encrypt ' ],
133+ 'decrypt_callback ' => [$ this , 'decrypt ' ],
134+ ]);
135+ Mage::app ()->getCache ()->clean ('config ' );
136+ }
132137
133138 if (\Composer \InstalledVersions::isInstalled ('mahocommerce/module-mcrypt-compat ' )) {
134139 $ output ->writeln ('' );
@@ -231,7 +236,11 @@ protected function recryptCoreConfigDataTable(OutputInterface $output, \Maho\Db\
231236
232237 public function decrypt (#[\SensitiveParameter] string $ data ): string
233238 {
234- if ($ this ->isOldEncryptionKeyM1 && function_exists ('mcrypt_module_open ' )) {
239+ if ($ this ->isOldEncryptionKeyM1 ) {
240+ if (!function_exists ('mcrypt_module_open ' )) {
241+ return '' ;
242+ }
243+
235244 $ key = $ this ->oldEncryptionKey ;
236245 $ handler = mcrypt_module_open (MCRYPT_BLOWFISH , '' , MCRYPT_MODE_ECB , '' ); // @phpstan-ignore constant.notFound,constant.notFound
237246 $ initVector = mcrypt_create_iv (mcrypt_enc_get_iv_size ($ handler ), MCRYPT_RAND ); // @phpstan-ignore function.notFound,function.notFound,constant.notFound
0 commit comments