robrichards/xmlseclibs

SignatureValue differs from PKI

Opened this issue · 0 comments

I have problems with the XML signing using multiple algoritms, it always says my SignatureValue differs from PKI

I signed this XML, only the DE element:
https://pastebin.com/uvbu2ymB

This is the code:

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

// Load the XML to be signed
$doc = new DOMDocument();
$doc->load('xml.xml');

// Create a new Security object 
$objDSig = new XMLSecurityDSig('');
// Use the c14n exclusive canonicalization
$objDSig->setCanonicalMethod(XMLSecurityDSig::C14N);

$root = $doc->documentElement;

$objDSig->addReference(
    $root->childNodes[0]->getElementsByTagName('DE')[0], 
    XMLSecurityDSig::SHA256, 
    array('http://www.w3.org/2000/09/xmldsig#enveloped-signature','http://www.w3.org/2001/10/xml-exc-c14n#'),
    array('force_uri'=>true,'overwrite'=>true,'overwrite_id'=>$deIDconDV,'id_name'=>$deIDconDV)
);
// Create a new (private) Security key
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, array('type'=>'private'));
/*
If key has a passphrase, set it using
*/
// Load the private key
$objKey->passphrase = '***************';
$objKey->loadKey(file_get_contents('key.pem'));

// Sign the XML file
$objDSig->sign($objKey);

// Add the associated public key to the signature
$objDSig->add509Cert(file_get_contents('pubkey.pem'));
$objDSig->appendSignature($root->childNodes[0]);

And this is the XML signed: https://pastebin.com/HNDX3KCf

I have to attach this XML signed on SoapClient using ANYXSD, but having big problem with SignatureValue being different from PKI, i don't understand what it means.

I'm doing something Wrong ?