Thanks for your reply. Here is what I have so far.
<?php
require(dirname(__FILE__) . '/xmlseclibs.php');
if (file_exists(dirname(__FILE__) . '/sign-basic-test.xml')) {
unlink(dirname(__FILE__) . '/sign-basic-test.xml');
}
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$tobesigned = $dom->createElement('ToBeSigned');
$value = $dom->createElement('Value', 'Hello World');
$dom->appendChild($tobesigned);
$tobesigned->appendChild($value);
$objDSig = new XMLSecurityDSig();
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
$node = $objDSig->addObject($dom->documentElement);
$objDSig->addReference($node, XMLSecurityDSig::SHA1, NULL, array('force_uri' => true));
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private'));
/* load private key */
$objKey->loadKey(dirname(__FILE__) . '/privkey.pem', TRUE);
/* if key has Passphrase, set it using $objKey->passphrase = <passphrase> " */
$objDSig->sign($objKey);
/* Add associated public key */
$objDSig->add509Cert(file_get_contents(dirname(__FILE__) . '/mycert.pem'));
$objDSig->appendSignature($dom->documentElement);
$dom->save(dirname(__FILE__) . '/sign-basic-test.xml');
echo "DONE";
?>
<?xml version="1.0" encoding="UTF-8"?>
<ToBeSigned>
<Value>Hello World</Value>
<ds:SignedInfo>
<ds:Reference URI="#pfx394571ed-522b-425e-be9a-2b47c8bce5e2">
<ds:DigestValue>Ao8wIiNH7AoEbyvddx1Dapy6CY4=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue> .... ZL30WTxTH09679o3/OUF8dodsRqa46++Dqm .... </ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate> .... MIIEVDCCAzygAwIBAgIJAPTrkMJbCOr1MA0G .... </ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
<ds:Object Id="pfx394571ed-522b-425e-be9a-2b47c8bce5e2">
<ToBeSigned>
<Value>Hello World</Value>
</ToBeSigned>
</ds:Object>
</ds:Signature>
</ToBeSigned>
The final challenge is to have the XML file generated without line no 2, 3 and 26 (the last one), so you end up with a correct ENVELOPING signature, with the <ds:Signature> as the starting and ending element.
Regards,
Lars