Jan Walraven
DevOps



Categories:
  • Arduino (2)
  • CSS (3)
  • Docker (10)
  • ESXi (1)
  • Git (4)
  • Google Cloud (2)
  • Javascript (6)
  • Linux (31)
  • Mac (6)
  • Magento (4)
  • Mysql (13)
  • PHP (9)
  • Zend framework 2 (9)
  • Posted on July 26, 2013

    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);