Is there any documentation for xmlseclibs?

I signed XML, but I do not know how to include the KeyValue element in the signature. Having some documentation will save a lot of time.

The code below (if you're interested) is what I managed to do with xmlseclibs:

<?php
require('xmlseclibs.php'); 

XML string

$getToken = '<getToken>
<item>
<Semilla>Random string</Semilla>
</item>
</getToken>';

Creating an XML Object (for Signing)

$getToken_DOMDocument = new DOMDocument(); 
$getToken_DOMDocument -> loadXml($getToken); 

Creating a signature object using xmlseclibs

$getToken_XMLSecurityDSig = new XMLSecurityDSig(); 
$getToken_XMLSecurityDSig -> setCanonicalMethod(XMLSecurityDSig::C14N); 

Trying to disable the ds: prefix which does not 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); 

Access to essential 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> */ 

XML object signing

$getToken_XMLSecurityDSig -> sign($XMLSecurityKey); 

Adding a public key

$getToken_XMLSecurityDSig -> add509Cert(file_get_contents('../../DTE/certificado/firma/certificado.pem')); 

Adding a signature envelope to an XML object

$getToken_XMLSecurityDSig -> appendSignature($getToken_DOMDocument -> documentElement); 

Saving a signed toa XML file

$getToken_DOMDocument -> save('sign-basic-test.xml'); 
?>

Additional information will also be liked in this library:

  • Know the official and reliable repository so that the library is not corrupted.
  • "ds:" ( , XML, , ).
  • X Base64.
  • ( ).

.

+4
2

xmldsig XMLSecLibs

:

public function testSign()
{
    $getToken = '<getToken>
    <item>
    <Semilla>Random string</Semilla>
    </item>
    </getToken>';

    $data = new DOMDocument();
    $data->loadXml($getToken);

    $adapter = new XmlseclibsAdapter();
    $adapter
        ->setPrivateKey(file_get_contents('privateKey.pem'))
        ->setPublicKey(file_get_contents('publicKey.pem'))
        ->setCanonicalMethod('http://www.w3.org/2001/10/xml-exc-c14n#')
        ->sign($data);

        echo $data->saveXML();
    );
}
+2

All Articles