8

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

13

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;
9

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

  • This happen to me after copy database from server to local, copying also key help in that keys. – BartZalas Jul 31 at 20:35
3

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

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, privacy policy and cookie policy

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