Sign xml with xmlseclibs php

378 views
Skip to first unread message

Nathan Feitoza

unread,
Aug 15, 2017, 10:57:40 AM8/15/17
to xmlseclibs

I have sign the xml for send in soap request. I use the xmlseclibs. The lib sign correctly xml, but not the way I need it.


The Xmls: https://pastebin.com/qyA8fmbi


My code for sign the Xml:


use RobRichards\XMLSecLibs\XMLSecurityDSig;
use RobRichards\XMLSecLibs\XMLSecurityKey;

function signXML($xml) {

$doc = new DOMDocument('1.0','UTF-8');
$doc->loadXML($xml);
$objDSig = new XMLSecurityDSig('');
$objDSig->setCanonicalMethod(XMLSecurityDSig::C14N);

$objDSig->addReference(
    $doc, 
    XMLSecurityDSig::SHA1,
        ['http://www.w3.org/2000/09/xmldsig#enveloped-signature',
    'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'],
    ["force_uri"=>true]
);
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private'));
$privkey = 'cert_pem/privkey.pem';
$objKey->loadKey($privkey, TRUE);
$objDSig->sign($objKey);
$pubkey = 'cert_pem/mycert.pem';
$objDSig->add509Cert(file_get_contents($pubkey));
$objDSig->appendSignature($doc->documentElement);
return $doc->saveXML();

}

Please, someone save me!




Reply all
Reply to author
Forward
0 new messages