示例#1
0
 /**
  * Defined by Zend\Filter\FilterInterface
  *
  * Encrypts $value with the defined settings
  *
  * @param  string $value The content to encrypt
  * @throws Exception\InvalidArgumentException
  * @return string The encrypted content
  */
 public function encrypt($value)
 {
     // compress prior to encryption
     if (!empty($this->compression)) {
         $compress = new Compress($this->compression);
         $value = $compress($value);
     }
     try {
         $encrypted = $this->blockCipher->encrypt($value);
     } catch (CryptException\InvalidArgumentException $e) {
         throw new Exception\InvalidArgumentException($e->getMessage());
     }
     return $encrypted;
 }
示例#2
0
 /**
  * Ensures that the filter allows de/encryption with compression
  *
  * @return void
  */
 public function testEncryptionWithDecryptionAndCompressionMcrypt()
 {
     if (version_compare(phpversion(), '5.4', '>=')) {
         $this->markTestIncomplete('Code to test is not compatible with PHP 5.4 ');
     }
     if (!extension_loaded('bz2')) {
         $this->markTestSkipped('This adapter needs the bz2 extension');
     }
     $filter = new BlockCipherEncryption(array('key' => 'testkey'));
     $filter->setVector('1234567890123456');
     $filter->setCompression('bz2');
     $output = $filter->encrypt('teststring');
     $this->assertNotEquals('teststring', $output);
     $input = $filter->decrypt($output);
     $this->assertEquals('teststring', trim($input));
 }
示例#3
0
 /**
  * Ensures that the filter allows de/encryption with compression
  *
  * @return void
  */
 public function testEncryptionWithDecryptionAndCompressionMcrypt()
 {
     if (!extension_loaded('bz2')) {
         $this->markTestSkipped('This adapter needs the bz2 extension');
     }
     $filter = new BlockCipherEncryption(array('key' => 'testkey'));
     $filter->setVector('1234567890123456');
     $filter->setCompression('bz2');
     $output = $filter->encrypt('teststring');
     $this->assertNotEquals('teststring', $output);
     $input = $filter->decrypt($output);
     $this->assertEquals('teststring', trim($input));
 }