コード例 #1
0
ファイル: Mcrypt.php プロジェクト: jasmun/Noco100
 /**
  * Defined by IfwPsn_Vendor_Zend_Filter_Interface
  *
  * Decrypts $value with the defined settings
  *
  * @param  string $value Content to decrypt
  * @return string The decrypted content
  */
 public function decrypt($value)
 {
     $cipher = $this->_openCipher();
     $this->_initCipher($cipher);
     $decrypted = mdecrypt_generic($cipher, $value);
     mcrypt_generic_deinit($cipher);
     $this->_closeCipher($cipher);
     // decompress after decryption
     if (!empty($this->_compression)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Filter/Decompress.php';
         $decompress = new IfwPsn_Vendor_Zend_Filter_Decompress($this->_compression);
         $decrypted = $decompress->filter($decrypted);
     }
     return $decrypted;
 }
コード例 #2
0
ファイル: Openssl.php プロジェクト: jasmun/Noco100
 /**
  * Defined by IfwPsn_Vendor_Zend_Filter_Interface
  *
  * Decrypts $value with the defined settings
  *
  * @param  string $value Content to decrypt
  * @return string The decrypted content
  * @throws IfwPsn_Vendor_Zend_Filter_Exception
  */
 public function decrypt($value)
 {
     $decrypted = "";
     $envelope = current($this->getEnvelopeKey());
     if (count($this->_keys['private']) !== 1) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Filter/Exception.php';
         throw new IfwPsn_Vendor_Zend_Filter_Exception('Please give a private key for decryption with Openssl');
     }
     if (!$this->_package && empty($envelope)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Filter/Exception.php';
         throw new IfwPsn_Vendor_Zend_Filter_Exception('Please give a envelope key for decryption with Openssl');
     }
     foreach ($this->_keys['private'] as $key => $cert) {
         $keys = openssl_pkey_get_private($cert, $this->getPassphrase());
     }
     if ($this->_package) {
         $details = openssl_pkey_get_details($keys);
         if ($details !== false) {
             $fingerprint = md5($details['key']);
         } else {
             $fingerprint = md5("ZendFramework");
         }
         $count = unpack('ncount', $value);
         $count = $count['count'];
         $length = 2;
         for ($i = $count; $i > 0; --$i) {
             $header = unpack('H32print/nsize', substr($value, $length, 18));
             $length += 18;
             if ($header['print'] == $fingerprint) {
                 $envelope = substr($value, $length, $header['size']);
             }
             $length += $header['size'];
         }
         // remainder of string is the value to decrypt
         $value = substr($value, $length);
     }
     $crypt = openssl_open($value, $decrypted, $envelope, $keys);
     openssl_free_key($keys);
     if ($crypt === false) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Filter/Exception.php';
         throw new IfwPsn_Vendor_Zend_Filter_Exception('Openssl was not able to decrypt you content with the given options');
     }
     // decompress after decryption
     if (!empty($this->_compression)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Filter/Decompress.php';
         $decompress = new IfwPsn_Vendor_Zend_Filter_Decompress($this->_compression);
         $decrypted = $decompress->filter($decrypted);
     }
     return $decrypted;
 }