Jan Walraven
DevOps



Categories:
  • Arduino (2)
  • CSS (3)
  • Docker (11)
  • ESXi (1)
  • Git (4)
  • Google Cloud (3)
  • Javascript (6)
  • Kubernetes (4)
  • Linux (36)
  • Mac (7)
  • Magento (4)
  • Mysql (14)
  • 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);