estrelow / Perl-LibXML-Sec

Perl bindings for xmlsec
MIT License
0 stars 0 forks source link

Migrate shell with xmlsec1 to this module ? #1

Open togro opened 4 years ago

togro commented 4 years ago

This shell :

xmlsec1 --sign --privkey-pem MyCert.pm,MyCert.pm \ --insecure \ --node-xpath "(//*[local-name()='Signature' and namespace-uri()='http://www.w3.org/2000/09/xmldsig#'])[last()]# " \ --id-attr:Id "http://www.w3.org/2000/09/xmldsig#:Signature" \ --id-attr:Id "http://www.w3.org/2000/09/xmldsig#:SignatureValue" input.xml > output.xml

Can it be implemented with this module in perl?

estrelow commented 4 years ago

I haven't been able to work on this for some months due to the pandemic situation. I still got a long backlog. In your case, it would be something like:

my $signer=XML::LibxXML::xmlsec->new();
$signer->loadpkey(PEM => 'MyCert.pm');
my $doc=XML::LibXML->load_xml(location => 'input.xml');
for ($doc->find("(//*[local-name()='Signature' and namespace-uri()='http://www.w3.org/2000/09/xmldsig#'])[last()]# ")) {
   $signer->signdoc($doc, 'id-attr' => 'Id', node => $_);
}
$doc->toFile('output.xml');