Recover credentials from a Magento installation

In case you ever find yourself trying to recover an API login and transaction key from a Magento installation, you’re in the right place.  What makes this slightly more difficult than reading a value from a config file is that Magento Enterprise encrypts the values.  So this is how to decrypt them.

First off, find the login and trans_key in the database for your Magento installation:

SELECT VALUE FROM core_config_data WHERE path IN ("payment/authorizenet/login", "payment/authorizenet/trans_key");

Next, use this code to decrypt the values (the values I’ve provided below are fake):

/* Substitute appropriate Mage path: */
$hlp = Mage::helper('core');
echo ($hlp->decrypt("0:2:31cd17ea0becc0:d67642b7da2fab==") . "\n");
echo ($hlp->decrypt("0:2:c4b2ee0255d1a5:abc06b1bcb3394==") . "\n");