I want to save encrypted value in core_config_data
while setup upgrade without using config.xml
. I am trying to use data patch file
Vendor\Credentials\Setup\Patch\Data\AddData.php
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Config\Model\Config\Backend\Encrypted;
use Magento\Framework\Encryption\EncryptorInterface;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
EncryptorInterface $_encryptor,
WriterInterface $configWriter
)
{
$this->moduleDataSetup=$moduleDataSetup;
$this->_encryptor = $_encryptor;
$this->configWriter = $configWriter;
}
$this->moduleDataSetup->startSetup();
$privateKey = $encrypted = $this->_encryptor->encrypt($value);
$publicKey = $encrypted = $this->_encryptor->encrypt($value);
$this->configWriter->save(self::XML_PATH_PRIVATE_API_KEY, $privateKey, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0);
$this->configWriter->save(self::XML_PATH_ENABLED, 1, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0);
$this->moduleDataSetup->endSetup();
But entry is not saving. I have checked patch table entry and here patch get register.