10

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

5 Answers 5

23

Go to Below file:

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

And Update Below Code on decrypt() method:

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

return $plainText ?: '';
3
15

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

2
  • 1
    This happen to me after copy database from server to local, copying also key help in that keys.
    – BartZalas
    Jul 31, 2019 at 20:35
  • 1
    perfect answer with explanation!!! made my day :) +1 Nov 8, 2019 at 6:48
6

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..!!

2
4

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
1
3

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 : '';
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.