muhammadmian/magento-2-crypt-key-replace

There is no license information available for the latest version (1.0.1) of this package.

Replaces Main Crypt Key with one configured in admin

1.0.1 2021-04-22 17:30 UTC

This package is not auto-updated.

Last update: 2025-05-17 10:30:11 UTC


README

Releases

Tested On

  • Magento 2.3
  • Magento 2.4

Problem Explained

If you've migrated magento from one server to another, but you cannot directly edit your env.php file to change your Crypt Key, this module will help you to do that in admin.

Magento's built in function to replace Crypt key will not work if you are still working with data that has already been encrypted with a different Crypt key.

This is because magento adds an index position of the crypt key used from the crypt key array to the encrypted data.

E.g. Old Setup:
Crypt Key Array:

[ 
    0 => OLD_CRYPT_KEY 
]

Previously Encrypted Data Value: [0]:34JHSDJ3H4JHDFJH34JJHFJHDFJHDF (SUCCESS)

New Setup:
If you use Magento's built-in feature to add a new crypt key, it will be added as the 2nd index of the array.
Crypt Key Array:

[ 
    0 => NEW_CRYPT_KEY
    1 => OLD_CRYPT_KEY 
]

Previously Encrypted Data Value: [0]:34JHSDJ3H4JHDFJH34JJHFJHDFJHDF (FAIL)

The index 0 (Zero) of the crypt key array is no longer the old encryption key thus it will fail to decrypt the data and give up.

Solution

This module adds the encryption key configured in magento admin as the first item in the crypt key array.

PLEASE NOTE: Any new data encrypted with the new encryption key will not decrypt

How to use

Simply install the module using composer.
composer require muhammadmian/magento-2-crypt-key-replace

Admin Config
Set the following config to YES and configure your new crypt key
Store > Configuration > Advanced > System > Enable Crypt Key Override

Enjoy.