Question

I did migration Magento 1 to Magento 2.3.0 all is good but when I create customer form both of side (front and admin) I got the error related to decrypt even I can not edit the customer when I click on save same error has occurred.

Below error is :

Fatal error: Uncaught TypeError: Return value of Magento\Framework\Encryption\Adapter\SodiumChachaIetf::decrypt() must be of the type string, boolean returned in public_html/vendor/magento/framework/Encryption/Adapter/SodiumChachaIetf.php:68 Stack trace: #0 public_html/vendor/magento/framework/Encryption/Encryptor.php(358): Magento\Framework\Encryption\Adapter\SodiumChachaIetf->decrypt('"\x10\x88\x8E\xB5\x851;H\xB1\x12\xE1aaP...')

#1 /public_html/vendor/dotmailer/dotmailer-magento2-extension/Helper/Data.php(744): Magento\Framework\Encryption\Encryptor->decrypt('IhCIjrWFMTtIsRL...')

#2 /public_html/vendor/dotmailer/dotmailer-magento2-extension/Helper/Data.php(203): Dotdigitalgroup\Email\Helper\Data->getApiPassword(Object(Magento\Store\Model\Website\Interceptor))

#3 public_html/vendor/dotmailer/dotmailer-magento2-extens in /public_html/vendor/magento/framework/Encryption/Adapter/SodiumChachaIetf.php on line 68

Was it helpful?

Solution

Go to Below file:

vendor/magento/framework/Encryption/Adapter/SodiumChachaIetf.php

And Update Below Code:

$plainText = sodium_crypto_aead_chacha20poly1305_ietf_decrypt(
            $payload,
            $nonce,
            $nonce,
            $this->key
        );
        if ($plainText == false)
        {
          return "";
        }
        return $plainText;

OTHER TIPS

Looks like you are using the wrong crypt key.

You should keep the key from your previews configuration:

app/etc/local.xml [Magento 1.x]

<?xml version="1.0"?>
<config>
  <global>
    <install>
      <date>{{date}}</date>
    </install>
    <crypt>
       <key>123456_same_old_key_7890</key>
    </crypt>
[...]

And replace the new one in the new project:

app/etc/env.php [Magento 2.x]

<?php
[...],
'crypt' => [
    'key' => '123456_same_old_key_7890'
],
[...]

Source: https://github.com/magento/magento2/issues/19590

Modifying the core class is not recommended at all. The issue is not with the class vendor/magento/framework/Encryption/Adapter/SodiumChachaIetf.php

But the issue with the crypt key added to your app/etc/env.php

The reason of this issue is the crypt key is mismatched. You must have taken the database dump from any other instance and trying to run with your current instance. So along with database you need to get the crypt key from the same setup where from you got the db dump.

Just update the crypt key in env.php and it will work fine.

The fix is to use same crypt key of the installation from where db is being used.

Hope it is explained.

Mark me up if was helpful. Happy coding..!!

Go to this file:

vendor/magento/framework/Encryption/Adapter/SodiumChachaIetf.php

And update below code:

 public function decrypt(string $data): string
    {
        $nonce = mb_substr($data, 0, SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES, '8bit');
        $payload = mb_substr($data, SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES, null, '8bit');

        $plainText = sodium_crypto_aead_chacha20poly1305_ietf_decrypt(
            $payload,
            $nonce,
            $nonce,
            $this->key
        );

        return (string) $plainText;
    }

Just change the function return type: From

return $plainText

to

return (string) $plainText

More an FYI still in 2.3 develop branch.

https://github.com/magento/magento2/blob/2.3-develop/lib/internal/Magento/Framework/Encryption/Adapter/SodiumChachaIetf.php

Official magento fix is this

    /**
     * Decrypt a string
     *
     * @param string $data
     * @return string
     */
    public function decrypt(string $data): string
    {
        $nonce = mb_substr($data, 0, SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES, '8bit');
        $payload = mb_substr($data, SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES, null, '8bit');
        try {
            $plainText = sodium_crypto_aead_chacha20poly1305_ietf_decrypt(
                $payload,
                $nonce,
                $nonce,
                $this->key
            );
        } catch (\SodiumException $e) {
            $plainText = '';
        }
        return $plainText !== false ? $plainText : '';
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top