I have signed the XML but I don't know how to include KeyValue element in the signature. Having some documentation would save a lot of time.
The code below (if you are interested) is what I managed to do with xmlseclibs so far:
<?php
require('xmlseclibs.php');
XML string
$getToken = '<getToken>
<item>
<Semilla>Random string</Semilla>
</item>
</getToken>';
Creating XML object (to sign)
$getToken_DOMDocument = new DOMDocument();
$getToken_DOMDocument -> loadXml($getToken);
Creating the signature object with xmlseclibs
$getToken_XMLSecurityDSig = new XMLSecurityDSig();
$getToken_XMLSecurityDSig -> setCanonicalMethod(XMLSecurityDSig::C14N);
Trying to turn off the ds: prefix which didn't work
$options['prefix'] = '';
$options['prefix_ns'] = '';
$options['force_uri'] = TRUE;
$options['id_name'] = 'ID';
$getToken_XMLSecurityDSig -> addReference($getToken_DOMDocument, XMLSecurityDSig::SHA1, array('http://www.w3.org/2000/09/xmldsig#enveloped-signature', 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'), $options);
Accessing the necessary key data
$XMLSecurityKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private'));
$XMLSecurityKey -> loadKey('../../DTE/certificado/firma/certificado.pem', TRUE);
/* if key has Passphrase, set it using $objKey -> passphrase = <passphrase> */
Signing the XML object
$getToken_XMLSecurityDSig -> sign($XMLSecurityKey);
Adding the public key
$getToken_XMLSecurityDSig -> add509Cert(file_get_contents('../../DTE/certificado/firma/certificado.pem'));
Appending the enveloped signature to the XML object
$getToken_XMLSecurityDSig -> appendSignature($getToken_DOMDocument -> documentElement);
Saving the signed XML code toa file
$getToken_DOMDocument -> save('sign-basic-test.xml');
?>
Additionaly would also like from this library:
- Know official and trustable repository to ensure the library is not corrupted.
- Turning off the "ds:" prefix (because nor the example nor the documentation of the XML I am producing includes such prefix).
- Linebreaks every X characters in the Base64 type values.
- Full indentation (otherwise none at all).
I got the library from enter link description here
Thanks in advance.