Exemple #1
0
 /**
  * Defined by Zend\Filter\Filter
  *
  * Encrypts the file $value with the defined settings
  *
  * @param  string|array $value Full path of file to change or $_FILES data array
  * @return string|array The filename which has been set, or false when there were errors
  * @throws Exception\InvalidArgumentException
  * @throws Exception\RuntimeException
  */
 public function filter($value)
 {
     // An uploaded file? Retrieve the 'tmp_name'
     $isFileUpload = is_array($value) && isset($value['tmp_name']);
     if ($isFileUpload) {
         $uploadData = $value;
         $value = $value['tmp_name'];
     }
     if (!file_exists($value)) {
         throw new Exception\InvalidArgumentException("File '{$value}' not found");
     }
     if (!isset($this->filename)) {
         $this->filename = $value;
     }
     if (file_exists($this->filename) and !is_writable($this->filename)) {
         throw new Exception\RuntimeException("File '{$this->filename}' is not writable");
     }
     $content = file_get_contents($value);
     if (!$content) {
         throw new Exception\RuntimeException("Problem while reading file '{$value}'");
     }
     $encrypted = parent::filter($content);
     $result = file_put_contents($this->filename, $encrypted);
     if (!$result) {
         throw new Exception\RuntimeException("Problem while writing file '{$this->filename}'");
     }
     if ($isFileUpload) {
         $uploadData['tmp_name'] = $this->filename;
         return $uploadData;
     }
     return $this->filename;
 }
 /**
  * Ensures that the encryption works fine
  */
 public function testEncryptBlockCipher()
 {
     if (!extension_loaded('mcrypt')) {
         $this->markTestSkipped('Mcrypt extension not installed');
     }
     $encrypt = new EncryptFilter(array('adapter' => 'BlockCipher', 'key' => 'testkey'));
     $encrypt->setVector('1234567890123456890');
     $encrypted = $encrypt->filter('test');
     $this->assertEquals($encrypted, 'ec133eb7460682b0020b736ad6d2ef14c35de0f1e5976330ae1dd096ef3b4cb7MTIzNDU2Nzg5MDEyMzQ1NoZvxY1JkeL6TnQP3ug5F0k=');
 }
Exemple #3
0
 /**
  * Defined by Zend\Filter\Filter
  *
  * Encrypts the file $value with the defined settings
  *
  * @param  string $value Full path of file to change
  * @return string The filename which has been set, or false when there were errors
  * @throws Exception\InvalidArgumentException
  * @throws Exception\RuntimeException
  */
 public function filter($value)
 {
     if (!file_exists($value)) {
         throw new Exception\InvalidArgumentException("File '{$value}' not found");
     }
     if (!isset($this->filename)) {
         $this->filename = $value;
     }
     if (file_exists($this->filename) and !is_writable($this->filename)) {
         throw new Exception\RuntimeException("File '{$this->filename}' is not writable");
     }
     $content = file_get_contents($value);
     if (!$content) {
         throw new Exception\RuntimeException("Problem while reading file '{$value}'");
     }
     $encrypted = parent::filter($content);
     $result = file_put_contents($this->filename, $encrypted);
     if (!$result) {
         throw new Exception\RuntimeException("Problem while writing file '{$this->filename}'");
     }
     return $this->filename;
 }
Exemple #4
0
 /**
  * @dataProvider returnUnfilteredDataProvider
  * @return void
  */
 public function testReturnUnfiltered($input)
 {
     if (!extension_loaded('mcrypt')) {
         $this->markTestSkipped('Mcrypt extension not installed');
     }
     $encrypt = new EncryptFilter(array('adapter' => 'BlockCipher', 'key' => 'testkey'));
     $encrypt->setVector('1234567890123456890');
     $encrypted = $encrypt->filter($input);
     $this->assertEquals($input, $encrypted);
 }