本文整理汇总了PHP中DOMElement::C14N方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMElement::C14N方法的具体用法?PHP DOMElement::C14N怎么用?PHP DOMElement::C14N使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMElement
的用法示例。
在下文中一共展示了DOMElement::C14N方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function it_appends_html_node(\DOMElement $element, \DOMElement $node, \DeForm\Node\HtmlNode $htmlNode)
{
$node->C14N()->willReturn('<input />');
$element->appendChild($node)->shouldBeCalled();
$htmlNode->getDomElement()->willReturn($node);
$this->appendChild($htmlNode);
}
示例2: two
function two()
{
$root = new DOMElement('root');
$child = new DOMElement('child');
$root->appendChild($child);
var_dump($root->C14N());
}
示例3: canonicalize
protected static function canonicalize(DOMElement $node)
{
$canonicalized = $node->C14N(true, false, null);
return $canonicalized;
}
示例4: zSignXML
/**
* zSignXML
* Método que provê a assinatura do xml conforme padrão SEFAZ
* @param DOMDocument $xmldoc
* @param DOMElement $root
* @param DOMElement $node
* @param resource $objSSLPriKey
* @return string xml assinado
* @internal param DOMDocument $xmlDoc
*/
private function zSignXML($xmldoc, $root, $node, $objSSLPriKey)
{
$nsDSIG = 'http://www.w3.org/2000/09/xmldsig#';
$nsCannonMethod = 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315';
$nsSignatureMethod = 'http://www.w3.org/2000/09/xmldsig#rsa-sha1';
$nsTransformMethod1 = 'http://www.w3.org/2000/09/xmldsig#enveloped-signature';
$nsTransformMethod2 = 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315';
$nsDigestMethod = 'http://www.w3.org/2000/09/xmldsig#sha1';
//pega o atributo id do node a ser assinado
$idSigned = trim($node->getAttribute("Id"));
//extrai os dados da tag para uma string na forma canonica
$dados = $node->C14N(true, false, null, null);
//calcular o hash dos dados
$hashValue = hash('sha1', $dados, true);
//converter o hash para base64
$digValue = base64_encode($hashValue);
//cria o node <Signature>
$signatureNode = $xmldoc->createElementNS($nsDSIG, 'Signature');
//adiciona a tag <Signature> ao node raiz
$root->appendChild($signatureNode);
//cria o node <SignedInfo>
$signedInfoNode = $xmldoc->createElement('SignedInfo');
//adiciona o node <SignedInfo> ao <Signature>
$signatureNode->appendChild($signedInfoNode);
//cria no node com o método de canonização dos dados
$canonicalNode = $xmldoc->createElement('CanonicalizationMethod');
//adiona o <CanonicalizationMethod> ao node <SignedInfo>
$signedInfoNode->appendChild($canonicalNode);
//seta o atributo ao node <CanonicalizationMethod>
$canonicalNode->setAttribute('Algorithm', $nsCannonMethod);
//cria o node <SignatureMethod>
$signatureMethodNode = $xmldoc->createElement('SignatureMethod');
//adiciona o node <SignatureMethod> ao node <SignedInfo>
$signedInfoNode->appendChild($signatureMethodNode);
//seta o atributo Algorithm ao node <SignatureMethod>
$signatureMethodNode->setAttribute('Algorithm', $nsSignatureMethod);
//cria o node <Reference>
$referenceNode = $xmldoc->createElement('Reference');
//adiciona o node <Reference> ao node <SignedInfo>
$signedInfoNode->appendChild($referenceNode);
//seta o atributo URI a node <Reference>
$referenceNode->setAttribute('URI', '#' . $idSigned);
//cria o node <Transforms>
$transformsNode = $xmldoc->createElement('Transforms');
//adiciona o node <Transforms> ao node <Reference>
$referenceNode->appendChild($transformsNode);
//cria o primeiro node <Transform> OBS: no singular
$transfNode1 = $xmldoc->createElement('Transform');
//adiciona o primeiro node <Transform> ao node <Transforms>
$transformsNode->appendChild($transfNode1);
//set o atributo Algorithm ao primeiro node <Transform>
$transfNode1->setAttribute('Algorithm', $nsTransformMethod1);
//cria outro node <Transform> OBS: no singular
$transfNode2 = $xmldoc->createElement('Transform');
//adiciona o segundo node <Transform> ao node <Transforms>
$transformsNode->appendChild($transfNode2);
//set o atributo Algorithm ao segundo node <Transform>
$transfNode2->setAttribute('Algorithm', $nsTransformMethod2);
//cria o node <DigestMethod>
$digestMethodNode = $xmldoc->createElement('DigestMethod');
//adiciona o node <DigestMethod> ao node <Reference>
$referenceNode->appendChild($digestMethodNode);
//seta o atributo Algorithm ao node <DigestMethod>
$digestMethodNode->setAttribute('Algorithm', $nsDigestMethod);
//cria o node <DigestValue>
$digestValueNode = $xmldoc->createElement('DigestValue', $digValue);
//adiciona o node <DigestValue> ao node <Reference>
$referenceNode->appendChild($digestValueNode);
//extrai node <SignedInfo> para uma string na sua forma canonica
$cnSignedInfoNode = $signedInfoNode->C14N(true, false, null, null);
//cria uma variavel vasia que receberá a assinatura
$signature = '';
//calcula a assinatura do node canonizado <SignedInfo>
//usando a chave privada em formato PEM
if (!openssl_sign($cnSignedInfoNode, $signature, $objSSLPriKey)) {
$msg = "Houve erro durante a assinatura digital.\n";
$this->zGetOpenSSLError($msg);
//while ($erro = openssl_error_string()) {
// $msg .= $erro . "\n";
//}
//throw new Exception\RuntimeException($msg);
}
//converte a assinatura em base64
$signatureValue = base64_encode($signature);
//cria o node <SignatureValue>
$signatureValueNode = $xmldoc->createElement('SignatureValue', $signatureValue);
//adiciona o node <SignatureValue> ao node <Signature>
$signatureNode->appendChild($signatureValueNode);
//cria o node <KeyInfo>
$keyInfoNode = $xmldoc->createElement('KeyInfo');
//.........这里部分代码省略.........