当前位置: 首页>>代码示例>>PHP>>正文


PHP XMLSecurityKey::encryptData方法代码示例

本文整理汇总了PHP中XMLSecurityKey::encryptData方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLSecurityKey::encryptData方法的具体用法?PHP XMLSecurityKey::encryptData怎么用?PHP XMLSecurityKey::encryptData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XMLSecurityKey的用法示例。


在下文中一共展示了XMLSecurityKey::encryptData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: encryptNode

 /**
  * Encrypt the selected node with the given key.
  *
  * @param XMLSecurityKey $objKey  The encryption key and algorithm.
  * @param bool           $replace Whether the encrypted node should be replaced in the original tree. Default is TRUE.
  * @throws Exception
  * @return DOMElement  The <xenc:EncryptedData>-element.
  */
 public function encryptNode($objKey, $replace = TRUE)
 {
     $data = '';
     if (empty($this->rawNode)) {
         throw new Exception('Node to encrypt has not been set');
     }
     if (!$objKey instanceof XMLSecurityKey) {
         throw new Exception('Invalid Key');
     }
     $doc = $this->rawNode->ownerDocument;
     $xPath = new DOMXPath($this->encdoc);
     $objList = $xPath->query('/xenc:EncryptedData/xenc:CipherData/xenc:CipherValue');
     $cipherValue = $objList->item(0);
     if ($cipherValue == NULL) {
         throw new Exception('Error locating CipherValue element within template');
     }
     switch ($this->type) {
         case DBSeller_Helper_Xml_Security_XMLSecEnc::Element:
             $data = $doc->saveXML($this->rawNode);
             $this->encdoc->documentElement->setAttribute('Type', DBSeller_Helper_Xml_Security_XMLSecEnc::Element);
             break;
         case DBSeller_Helper_Xml_Security_XMLSecEnc::Content:
             $children = $this->rawNode->childNodes;
             foreach ($children as $child) {
                 $data .= $doc->saveXML($child);
             }
             $this->encdoc->documentElement->setAttribute('Type', DBSeller_Helper_Xml_Security_XMLSecEnc::Content);
             break;
         default:
             throw new Exception('Type is currently not supported');
             return;
     }
     $encMethod = $this->encdoc->documentElement->appendChild($this->encdoc->createElementNS(DBSeller_Helper_Xml_Security_XMLSecEnc::XMLENCNS, 'xenc:EncryptionMethod'));
     $encMethod->setAttribute('Algorithm', $objKey->getAlgorith());
     $cipherValue->parentNode->parentNode->insertBefore($encMethod, $cipherValue->parentNode->parentNode->firstChild);
     $strEncrypt = base64_encode($objKey->encryptData($data));
     $value = $this->encdoc->createTextNode($strEncrypt);
     $cipherValue->appendChild($value);
     if ($replace) {
         switch ($this->type) {
             case DBSeller_Helper_Xml_Security_XMLSecEnc::Element:
                 if ($this->rawNode->nodeType == XML_DOCUMENT_NODE) {
                     return $this->encdoc;
                 }
                 $importEnc = $this->rawNode->ownerDocument->importNode($this->encdoc->documentElement, TRUE);
                 $this->rawNode->parentNode->replaceChild($importEnc, $this->rawNode);
                 return $importEnc;
                 break;
             case DBSeller_Helper_Xml_Security_XMLSecEnc::Content:
                 $importEnc = $this->rawNode->ownerDocument->importNode($this->encdoc->documentElement, TRUE);
                 while ($this->rawNode->firstChild) {
                     $this->rawNode->removeChild($this->rawNode->firstChild);
                 }
                 $this->rawNode->appendChild($importEnc);
                 return $importEnc;
                 break;
         }
     } else {
         return $this->encdoc->documentElement;
     }
 }
开发者ID:arendasistemasintegrados,项目名称:mateusleme,代码行数:69,代码来源:XMLSecEnc.php


注:本文中的XMLSecurityKey::encryptData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。