I'm trying to save / get encrypted data in my core_config_data table, such as an API key for example. In my system.xml
file I have it set to obscure:
<field id="my_access_token" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label" type="obscure">
<label>Access Token</label>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
</field>
And then in my config.xml
file I have:
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<test>
<api>
<my_access_token backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
</api>
</quickbooks>
</default>
</config>
This allows me to to retrieve / decrypt the value when using:
$this->scopeConfig->getValue('test/api/my_access_token', $storeScope);
However, if I want to save a new value with the following, it saves as plain text / unencrypted in the core_config_data
table
$this->configInterface->saveConfig('test/api/my_access_token', $myAccessTokenValue, 'default', 0);