6

I want to encrypt customer data like email,name,addresses. I have created new class to encrypt and decrypt data. For encryption , i'll have to use AccountController.php (i'll be overriding app/code/core/Mage/Customer module) Please let me know where should i use encryption function in createPostAction()

public function createPostAction()
{

    /** @var $session Mage_Customer_Model_Session */
    $session = $this->_getSession();
    if ($session->isLoggedIn()) {
        $this->_redirect('*/*/');
        return;
    }
    $session->setEscapeMessages(true); // prevent XSS injection in user input
    if (!$this->getRequest()->isPost()) {
        $errUrl = $this->_getUrl('*/*/create', array('_secure' => true));
        $this->_redirectError($errUrl);
        return;
    }

    $customer = $this->_getCustomer();

    try {
        $errors = $this->_getCustomerErrors($customer);

        if (empty($errors)) {
            $customer->save();
            $this->_dispatchRegisterSuccess($customer);
            $this->_successProcessRegistration($customer);
            return;
        } else {
            $this->_addSessionError($errors);
        }
    } catch (Mage_Core_Exception $e) {
        $session->setCustomerFormData($this->getRequest()->getPost());
        if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
            $url = $this->_getUrl('customer/account/forgotpassword');
            $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
            $session->setEscapeMessages(false);
        } else {
            $message = $e->getMessage();
        }
        $session->addError($message);
    } catch (Exception $e) {
        $session->setCustomerFormData($this->getRequest()->getPost())
            ->addException($e, $this->__('Cannot save the customer.'));
    }
    $errUrl = $this->_getUrl('*/*/create', array('_secure' => true));
    $this->_redirectError($errUrl);
}

Thanks in advance

5
  • No you don't want this. You destroy the whole logic in mysql, because you can't filter or order. Commented Feb 20, 2014 at 9:41
  • 1
    If your customer wants the data encrypted, encrypt the hard disk, use SSL/TLS everywhere and get a great admin Commented Feb 20, 2014 at 10:27
  • 1
    this will give no real gain, as the decryption keys are stored together with the db connection
    – Flyingmana
    Commented Feb 20, 2014 at 11:39
  • @Flyingmana But i'm using new class for encryption not encryptionkey that written in local.xml file. Commented Feb 20, 2014 at 11:44
  • 1
    its still in the same server in the same access scope as your local.xml
    – Flyingmana
    Commented Feb 20, 2014 at 11:45

2 Answers 2

11

Encrypting data isn't the issue. The following code snippet will encrypt data using Magento's build in encryption library

Mage::getModel('core/encryption')->encrypt('foobiedoo'); // returns encrypted string

The issue is that the data you're trying to encrypt is used all over Magento and is expected to be readily available. Like, for example, when a user logs in Magento needs to be able to search for the email address in the database.

Now you can probably get this to work by encrypting the input data when a user logs in for example but doing this for all the times Magento is using customer data will be a lot of work. Think about the customer data in the checkout, the customer grid in the admin area and so on.

My advice, encrypt only the most sensitive data like Credit Card numbers and invest your time in securing any 3th party extensions from SQL injections and that sort of attacks. The change of a hacker getting in to your installation and getting his hands on your customer data will be highly unlikely. Also there are companies that offer services to scan your webshop for possible security treads. That might be something you want to look into.

0
4

I think you should better write a observer, hook into customer_save_before and customer_save_after and maybe address, and other entities and then just run:

$encrypted = array_map((Mage::helper('core'), )$customer->getData());
$customer->setData($encrypted);

This is simplified! Of course you want only encrypt the data which needs to be encrypted. Especially the foreign keys, etc. shouldn't be broken.

And in the save_after you want to decrypt again everything.

6
  • Not sure why you got downvoted. The observers are a great approach. But you would still run into issues any time Magento needs the data I guess? Commented Feb 20, 2014 at 10:25
  • The idea is: Load encrypted data, decrypt them, so you can use them over the whole system. Problem with MySQL querying still exists, yes. You can't repair this idea. The approach is broken. Commented Feb 20, 2014 at 10:26
  • Overwrite all Resource classes of the customer model to decrypt whenever AddAttributeToFilter/Select is called on a customer collection would be required and much more. You probably wouldn't have this stable before Magento 2.0 launches ^^ Commented Feb 20, 2014 at 10:29
  • It is even worse, because encryption differs between upper and lowercase, mysql doesn't. and there is no way except CASE, CASe, CAsE, CaSE, cASE, CAse, ... to search for things. and ordering doesn't work too. Commented Feb 20, 2014 at 10:55
  • 1) Encryption is single way task we can encrypt data , but decryption requires at checkout,edit profile also backend. 2)Is it fine to use decryption function when ever require for e.g. in function > public function forgotPasswordPostAction() to search email 3) Actually i tried to encrypt data by using new function >public function encryption($userDatas) used this function in > public function createPostAction() in line > $customerForm->extractData($this->getRequest()) and got output as > Array ( [firstname] => encryptedFname [lastname] => encryptedLname [email] => encryptedEmail ) Commented Feb 20, 2014 at 11:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.