Jan Walraven
DevOps



Menu
Categories:
Posted on

Encrypt and decrypt data using ZF2


//add this to your class
use ZendCryptBlockCipher;

//Setup the encryption class to use AES
$cipher = BlockCipher::factory('mcrypt',
	array('algorithm' => 'aes')
);
//Set your encryption key/salt
$cipher->setKey('this is the encryption key');

//The text to encrypt
$text = 'This is the message to encrypt';

//Encrypt the data
$encrypted = $cipher->encrypt($text);

//Decrypt the data
$text = $cipher->decrypt($encrypted);