22

I'm working on a shipping module. In system.xml I set some fields to be backend_encrypted. Here is the node:

<client_id translate="label"> <label>Client ID</label> <frontend_type>obscure</frontend_type> <backend_model>adminhtml/system_config_backend_encrypted</backend_model> <sort_order>10</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </client_id> 

I need that value to pass using cURL to shipping API but, when I try to retrieve it using $this->getConfigData('client_id');, it come out encrypted.

I was looking in other modules and I see values stored the same but somehow, they manage to get the right value.

Any idea how to get it?

2 Answers 2

38

In order to use $this->getConfigData('client_id'); without manually decrypting it, you need to update your config.xml by adding <client_id backend_model="adminhtml/system_config_backend_encrypted" />, see example below

In your config.xml

... <default> <carriers> <magepal> ...... <client_id backend_model="adminhtml/system_config_backend_encrypted" /> </magepal> </carriers> </default> </config> 
Sign up to request clarification or add additional context in comments.

2 Comments

Adding this will transparently decrypt the configuration values, which I suppose in 9 out of 10 cases is what is actually wanted. While Tim's solution works, I think this is the more correct answer.
^^ Whilst the accepted answer 'works', this definitely does seem more 'correct'.
32

Just use Mage::helper('core')->decrypt($this->getConfigData('client_id'));

2 Comments

works, thanks. but why I haven't see any reference to decrypt on any other module? And if you can help, I'm using it wrong, where it's not supposed to be?
You are doing everything right. If you will search Magento code for "decrypt" you will get plenty of references.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.