Resolve issues with encryption key
This article talks about how to fix the issues caused by the encryption key not being moved together with DB dump to the other environment.
Affected products and versions
- Adobe Commerce on cloud infrastructure 2.2.x, 2.3.x
Issue
After importing a database dump from Production to Staging/Integration environments, saved credit card numbers appear wrong and/or payments fail for payment integrations requiring usage of merchant credentials.
Cause
The encryption key used to encrypt sensitive data, like credit card numbers and merchant credentials, is not stored in the database, and therefore does not get transferred to other environment after database dump import/export.
Solution
You need to copy the encryption key from the source environment and add it to the destination environment.
To copy the encryption key:
- SSH to your project that was the source for the database dump, as described in SSH to environment in our developer documentation.
- Open
app/etc/env.php
in a text editor. - Copy the value of
key
forcrypt
.
return array ('crypt' => array ('key' => '<your encryption key>', ),);
To set the key value for the destination project:
- Open the Cloud Console and locate your project.
- Set the value of the CRYPT_KEY (in our developer documentation) variable, as described in Configure your project in our developer documentation. This will trigger the deployment process and
CRYPT_KEY
will be overridden in theapp/etc/env.php
file on every deployment.
Optionally, you can manually override the encryption key in the app/etc/env.php
file:
- SSH to the destination environment.
- Open
app/etc/env.php
in a text editor. - Paste the copied data as the
key
value forcrypt
. - Save the edited
env.php
. - Clean cache on the destination environment by running
bin/magento cache:clean
or in the Commerce Admin under System > Tools > Cache Management.