Open elvispdosreis opened 5 years ago
Creating multiple signatures isn't currently supported, You might be able to work around this by playing around with the sigNode property but have never personally tried it
I still can not do with the "robrichards/xmlseclibs" package I'm using "nfephp-org/sped-common" that serves my purposes
A library from a commercial party that 1) doesn't know how to write English docs 2) doesn't know how to use coding standards 3) puts image resources in a low-level library and 4) hasn't taken the effort to write any unit-tests 5) has zero contributors... Hmmm, I think I'll pass, but thanks for the shameless self-promotion all over this repository! :wave:
please someone on earth help us
@elvispdosreis your code is almost right.
You need to remove the loop inside sign function that will append to all InfNfse
tags with the same SIGNAGE.
Instead you need to loop over your XML and SIGN the first InfNfse
tags.
Also remove ['force_uri' => true] and place [ 'id_name' => 'Id', 'overwrite' => false] instead.
Pass $signRoot = false
too.
After all, just pass the $node where you want to append it like that:
// Find the first node using NS
$xpath = new DOMXPath($xml);
$xpath->registerNamespace('ns', "http://www.abrasf.org.br/nfse.xsd");
$node = $xpath->query("//ns:InfNfse")->item(0);
if (!isset($node)) {
$msg = "Tag <InfNfse> not found!";
throw new Exception($msg);
}
$newXML = this.signXML($xml, false, $node)
...
public function signXml($xml, $signRoot = true, $node = null){
...
// Sign using SHA-1
$objDSig->addReference(
($node)?$node:$xml,
XMLSecurityDSig::SHA1,
['http://www.w3.org/2000/09/xmldsig#enveloped-signature'],
['id_name' => 'Id', 'overwrite' => false]
);
...
if ($node) {
$objDSig->appendSignature($node->parentNode);
}
...
Cheers!
I have an xml document that I need to add multiple signatures in them, and I need to add the references,
<ds:Reference URI="">
to<ds:Reference URI="#NFSe201800000113740">