/** * 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; }
/** * 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)); }
/** * 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)); }