Resolve issues with encryption key

When you import a database dump to another environment, the encryption key remains in the source environment. This article explains how to transfer the encryption key to resolve payment and saved data issues.

Description description

Environment

Adobe Commerce on cloud infrastructure 2.4.x

Issue/Symptoms

After importing a database dump from Production to Staging/Integration environments, you experience one or more of the following:

  • Saved credit card numbers appear incorrect
  • Payments fail for payment integrations that require merchant credentials
  • Stored payment method data is corrupted

Cause

The encryption key used to encrypt sensitive data (such as credit card numbers and merchant credentials) is not stored in the database. Therefore, it is not transferred to other environments when you import or export a database dump.

Resolution resolution

You must copy the encryption key from the source environment and add it to the destination environment.

To copy the encryption key:

  1. SSH to your project that was the source for the database dump, as described in SSH to environment in our developer documentation.
  2. Open app/etc/env.php in a text editor.
  3. Copy the value of key for crypt.
return array(
    'crypt' => array(
        'key' => '',
    ),
);

To set the key value for the destination project:

  1. Open the Cloud Console and locate your project.
  2. 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 the app/etc/env.php file on every deployment.

Optionally, you can manually override the encryption key in the app/etc/env.php file:

  1. SSH to the destination environment.
  2. Open app/etc/env.php in a text editor.
  3. Paste the copied data as the key value for crypt.
  4. Save the edited env.php.
  5. Clean cache on the destination environment by running bin/magento cache:clean or in the Commerce Admin under System > Tools > Cache Management.
recommendation-more-help
experience-cloud-kcs-help-kbarticles