本文整理汇总了PHP中XML::saveXML方法的典型用法代码示例。如果您正苦于以下问题:PHP XML::saveXML方法的具体用法?PHP XML::saveXML怎么用?PHP XML::saveXML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML
的用法示例。
在下文中一共展示了XML::saveXML方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signXML
/**
* Método que firma un XML utilizando RSA y SHA1
*
* Referencia: http://www.di-mgt.com.au/xmldsig2.html
*
* @param xml Datos XML que se desean firmar
* @param reference Referencia a la que hace la firma
* @return XML firmado o =false si no se pudo fimar
* @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
* @version 2015-09-02
*/
public function signXML($xml, $reference = '', $tag = null, $xmlns_xsi = false)
{
$doc = new XML();
$doc->loadXML($xml);
// crear nodo para la firma
$Signature = $doc->importNode((new XML())->generate(['Signature' => ['@attributes' => ['xmlns' => 'http://www.w3.org/2000/09/xmldsig#'], 'SignedInfo' => ['@attributes' => ['xmlns' => 'http://www.w3.org/2000/09/xmldsig#', 'xmlns:xsi' => $xmlns_xsi ? 'http://www.w3.org/2001/XMLSchema-instance' : false], 'CanonicalizationMethod' => ['@attributes' => ['Algorithm' => 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315']], 'SignatureMethod' => ['@attributes' => ['Algorithm' => 'http://www.w3.org/2000/09/xmldsig#rsa-sha1']], 'Reference' => ['@attributes' => ['URI' => $reference], 'Transforms' => ['Transform' => ['@attributes' => ['Algorithm' => 'http://www.w3.org/2000/09/xmldsig#enveloped-signature']]], 'DigestMethod' => ['@attributes' => ['Algorithm' => 'http://www.w3.org/2000/09/xmldsig#sha1']], 'DigestValue' => null]], 'SignatureValue' => null, 'KeyInfo' => ['KeyValue' => ['RSAKeyValue' => ['Modulus' => null, 'Exponent' => null]], 'X509Data' => ['X509Certificate' => null]]]])->documentElement, true);
// calcular DigestValue
if ($tag) {
$digest = base64_encode(sha1($doc->documentElement->getElementsByTagName($tag)->item(0)->C14N(), true));
} else {
$digest = base64_encode(sha1($doc->C14N(), true));
}
$Signature->getElementsByTagName('DigestValue')->item(0)->nodeValue = $digest;
// calcular SignatureValue
$SignedInfo = $doc->saveHTML($Signature->getElementsByTagName('SignedInfo')->item(0));
$firma = $this->sign($SignedInfo);
if (!$firma) {
return false;
}
$signature = wordwrap($firma, $this->config['wordwrap'], "\n", true);
// reemplazar valores en la firma de
$Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue = $signature;
$Signature->getElementsByTagName('Modulus')->item(0)->nodeValue = $this->getModulus();
$Signature->getElementsByTagName('Exponent')->item(0)->nodeValue = $this->getExponent();
$Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue = $this->getCertificate(true);
// agregar y entregar firma
$doc->documentElement->appendChild($Signature);
return $doc->saveXML();
}