Back to Top

Make encryptions in Opencart

Updated 15 July 2016

If you want to perform encryption then it is very easy to perform in Opencart as the Opencart provides the encryption library(encryption.php) to perform encryptions and decryptions. Actually, Opencart uses the Mcrypt encryption tool for the encryption. You can use any of your encryption key to hash for the encryption otherwise, it will use the key from the config.

So, if you are not using your key then you have to just put the below code to encrypt and decrypt data:

$string_to_encrypt = 'Hello';

$encrypted = $this->encryption->encrypt($string_to_encrypt);
// value of $encrypted is "9_wJveuFk5oBGivhquffHJyWKA5utvFuyTfaoIPZUwo," in my case

$decrypted = $this->encryption->decrypt($encrypted);

On decryption, the value will be decrypted back to ‘Hello’ on using the same key for the decryption.

If we want to use a different key for the encryption then we have to create the object of the encryption library and sending our key as an argument like in the below code:

$key = 'abcdef';
$crypt = new Encryption($key);
$string_to_encrypt = 'Hello';

$enc = $crypt->encrypt($string_to_encrypt);
$dec = $crypt->decrypt($enc);

We have to use the same key for the decryption for which we are performing the encryption.

Searching for an experienced
Opencart Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home