/** * Change encryption key * * @throws Exception * @param string $key * @return string */ public function changeEncryptionKey($key = null) { // prepare new key, encryptor and new file contents $file = Mage::getBaseDir('etc') . DS . 'local.xml'; if (!is_writeable($file)) { throw new Exception(Mage::helper('enterprise_pci')->__('File %s is not writeable.', realpath($file))); } $contents = file_get_contents($file); if (null === $key) { $key = md5(time()); } $this->_encryptor = clone Mage::helper('core')->getEncryptor(); $this->_encryptor->setNewKey($key); $contents = preg_replace('/<key><\\!\\[CDATA\\[(.+?)\\]\\]><\\/key>/s', '<key><![CDATA[' . $this->_encryptor->exportKeys() . ']]></key>', $contents); // update database and local.xml $this->beginTransaction(); try { $this->_reEncryptSystemConfigurationValues(); $this->_reEncryptCreditCardNumbers(); file_put_contents($file, $contents); $this->commit(); return $key; } catch (Exception $e) { $this->rollBack(); throw $e; } }