How to Encrypt and decrypt information in Magento

0 votes
530 views
asked Nov 16, 2016 in Magento by Suraj
How to Encrypt and decrypt information in Magento? Is there an inbuilt functionality to do this?

3 Answers

0 votes
answered Nov 16, 2016 by Johan

Encrypting a string in Magneto is really really. Magento will use the encryption key specified in the local.xml file:

<?php
$encryptedData = Mage::helper('core')->encrypt("This will be encrypted");

There is one problem that you may encounter that can be a little bit problematic but there is an easy work around. The encryption process will strip out non-printing characters or character it does not recognise. Easiest way to get about this is to base64 encode what you are about to encrypt:

<?php
$encryptedData = Mage::helper('core')->encrypt(base64_encode("\n\rI start with a carriage return"));

Decrypting is just as easy:

<?php
$decyptedData = Mage::helper('core')->decrypt($encryptedData);

Remember to base64_decode after decryption if you did base64 encode before encryption:

<?php
$decyptedData = base64_decode(Mage::helper('core')->decrypt($encryptedData));
0 votes
answered Nov 16, 2016 by Justin
NO! Never ever do this. Take your hands out.

You destroy the whole logic in mysql, because you can't filter or order.
0 votes
answered Nov 16, 2016 by Beak
Maybe you are talking about the SSL thing?

If this is already a running site with data populated in the database, I wont recommend doing something like this. This is likely to create issues with the old data unless you do the encryption manually on already happened entries.

Related questions

+2 votes
0 answers 284 views
+1 vote
1 answer 329 views
0 votes
1 answer 328 views
+1 vote
1 answer 487 views
0 votes
1 answer 428 views
0 votes
0 answers 227 views
...