コード例 #1
0
ファイル: NdJFileCrypt.php プロジェクト: ndejong/libs-php-NdJ
        /**
         * decrypt()
         *
         * @param string $filename
         * @param string $key
         */
        function decrypt($filename,$key) {
                //$this->out(__METHOD__,'debug');

                if(empty($key) || !is_string($key)) {
                        throw new Exception('No key provided to decrypt file against.');
                }

                // Check the source file exists
                if(!is_file($filename)) {
                        throw new Exception('Unable to locate file: '.$filename.' to decrypt.');
                }

                // Create a tempfile name
                $tempfile_filename = tempnam(sys_get_temp_dir(),'decrypt_').'.gz.nc';
                $target_filename = str_replace('.gz.nc','',$tempfile_filename);
                unlink($target_filename);

                // Copy the file to the temp
                copy($filename,$tempfile_filename);

                // Decrypt the file
                $cmd = $this->mcrypt_exec.' --decrypt --quiet --force --key "'.$key.'" --gzip '.$tempfile_filename;

                if(false === $this->SystemCommand->exec($cmd)) {
                        throw new Exception('Failed while calling mcrypt to decrypt: '.$filename);
                }
                unlink($tempfile_filename);

                // Check the decrypted file exists
                if(!is_file($target_filename)) {
                        throw new Exception('Could not locate decrypted file at: '.$target_filename);
                }

                return $target_filename;
        }
コード例 #2
0
ファイル: mysql.php プロジェクト: actcms/nowphp
 /**
  * 打开一个数据库连接
  * @author 欧远宁
  */
 private function open()
 {
     if (is_null($this->link)) {
         try {
             $this->link = new PDO($this->dsn, $this->user, $this->pwd);
             $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             //设置为打开异常反馈
             $this->link->exec("SET NAMES utf8");
             //使用utf8编码
         } catch (Exception $e) {
             throw new err($e->getMessage(), 100);
         }
     }
 }
コード例 #3
0
ファイル: ArrayValidator.php プロジェクト: fezfez/keep-update
 /**
  * @param class $contraint
  * @param string $contraintName
  * @param array $data
  * @throws ValidationException
  */
 private function execAnnotation($contraint, $contraintName, array $data)
 {
     if ($contraint instanceof Annotations\Chain) {
         if ($contraint->nullable === true && $data[$contraintName] === null) {
             return;
         } elseif (is_array($data[$contraintName]) === false) {
             throw new InvalidTypeException(sprintf('"%s" must be and array in "%s"', $contraintName, json_encode($data)));
         }
         try {
             $this->isValid($contraint->class, $data[$contraintName]);
         } catch (\Exception $e) {
             throw new ValidationException(sprintf('%s in "%s" from "%s"', $e->getMessage(), $contraintName, json_encode($data)));
         }
     } else {
         $contraint->exec($data[$contraintName]);
     }
 }