Magento decrypt() error

Unix

28 Jan 2019

Magento decrypt() error

Preston Garrison 0 Comments

Seeing errors like the following:

PHP Fatal error:  Uncaught TypeError: Return value of Magento\Framework\Encryption\Adapter\SodiumChachaIetf::decrypt() must be of the type string, boolean returned in /var/www/magento2/vendor/magento/fr                  amework/Encryption/Adapter/SodiumChachaIetf.php:68
Stack trace:
#0 /var/www/magento2/vendor/magento/framework/Encryption/Encryptor.php(358): Magento\Framework\Encryption\Adapter\SodiumChachaIetf->decrypt('\x1F\xB1\xE2?\xA6\xFB\t\xAB\x16\x12^\x0F\xCC\xFF\x8D...')
#1 /var/www/magento2/vendor/magento/module-config/Model/Config/Backend/Encrypted.php(111): Magento\Framework\Encryption\Encryptor->decrypt('H7HiP6b7CasWEl4...')
#2 /var/www/magento2/generated/code/Magento/Config/Model/Config/Backend/Encrypted/Interceptor.php(37): Magento\Config\Model\Config\Backend\Encrypted->processValue('0:3:H7HiP6b7Cas...')
#3 /var/www/magento2/vendor/magento/framework/App/Config/MetadataConfigTypeProcessor.php(131): Magento\Config\Model\Config\Backend\Encrypted\Interceptor->processValue('0:3:H7HiP6b7Cas...')
#4 /var/www/magento2/vendor/magento/framew in /var/www/magento2/vendor/magento/framework/Encryption/Adapter/SodiumChachaIetf.php on line 68

Fix by editing the php file

/var/www/magento2/vendor/magento/framework/Encryption/Adapter/SodiumChachaIetf.php 

and adding code

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

        if ($plainText == false)
        {
          return "";
        }


        return $plainText;