### Install xmlseclibs with Composer Source: https://github.com/robrichards/xmlseclibs/blob/master/README.md Use this command to install the xmlseclibs library using Composer. Ensure you have composer.phar available. ```sh php composer.phar require "robrichards/xmlseclibs" ``` -------------------------------- ### Basic XML Signing with SHA-256 Source: https://github.com/robrichards/xmlseclibs/blob/master/README.md This example demonstrates how to sign an XML document using SHA-256 with xmlseclibs. It includes loading the XML, setting canonicalization, adding a signature reference, loading a private key, signing, adding a certificate, and saving the signed XML. ```php use RobRichards\XMLSecLibs\XMLSecurityDSig; use RobRichards\XMLSecLibs\XMLSecurityKey; // Load the XML to be signed $doc = new DOMDocument(); $doc->load('./path/to/file/tobesigned.xml'); // Create a new Security object $objDSig = new XMLSecurityDSig(); // Use the c14n exclusive canonicalization $objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N); // Sign using SHA-256 $objDSig->addReference( $doc, XMLSecurityDSig::SHA256, array('http://www.w3.org/2000/09/xmldsig#enveloped-signature') ); // Create a new (private) Security key $objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, array('type'=>'private')); /* If key has a passphrase, set it using $objKey->passphrase = ''; */ // Load the private key $objKey->loadKey('./path/to/privatekey.pem', TRUE); // Sign the XML file $objDSig->sign($objKey); // Add the associated public key to the signature $objDSig->add509Cert(file_get_contents('./path/to/file/mycert.pem')); // Append the signature to the XML $objDSig->appendSignature($doc->documentElement); // Save the signed XML $doc->save('./path/to/signed.xml'); ``` -------------------------------- ### Retrieve X509 Certificate Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Get the X.509 certificate used for key operations. ```php XMLSecurityKey::getX509Certificate() ``` -------------------------------- ### Retrieve Validated Nodes Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Get the elements that have been signed by the digital signature. ```php XMLSecurityKey::getValidatedNodes() ``` -------------------------------- ### Get Cipher Value Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Retrieve the value of the cipher used for encryption. ```php XMLSecEnc::getCipherValue() ``` -------------------------------- ### Get X509 Thumbprint Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Retrieve the X.509 thumbprint of a certificate for identification and verification purposes. ```php XMLSecurityKey->getX509Thumbprint() ``` ```php XMLSecurityKey::getRawThumbprint($cert) ``` -------------------------------- ### Get Symmetric Key Size Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Determine the size of a symmetric key used in cryptographic operations. ```php XMLSecurityKey::getSymmetricKeySize() ``` -------------------------------- ### Add Chained Certificates Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Use the staticGet509XCerts method to add chained certificates from a PEM file into the X509Data node. ```php staticGet509XCerts() ``` -------------------------------- ### Use mhash for Hashing Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Attempt to use the 'mhash' extension for hashing when the 'hash' extension is not present. ```php mhash ``` -------------------------------- ### Initialize Random Number Generator Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Initialize the random number generator for mcrypt_create_iv to ensure proper security. ```php mcrypt_create_iv() ``` -------------------------------- ### Create DOM Document Fragment Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Fix a bug in decryptNode when dealing with node content to correctly create DOMDocumentFragments. ```php createDOMDocumentFragment() ``` -------------------------------- ### Add Padding for RSA_SHA1 Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Implement padding for RSA_SHA1 to ensure correct signature generation. ```php RSA_SHA1 ``` -------------------------------- ### Generate Session Key Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Improve the logic for generating session keys. ```php XMLSecurityKey::generateSessionKey() ``` -------------------------------- ### Inclusive Namespaces Prefix List Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Support for the InclusiveNamespaces prefix list within exclusive transformations. ```php InclusiveNamespaces ``` -------------------------------- ### Enable Enveloping Signature Creation Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Enable the creation of enveloping signatures, which is necessary for managed information cards. ```php enveloping signature ``` -------------------------------- ### Fallback to Built-in SHA1 Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Provide a fallback to the built-in SHA1 function if both 'hash' and 'mhash' extensions are unavailable, and throw an error for other missing hash types. ```php sha1 ``` -------------------------------- ### Fix CBC Mode Encryption Interoperability Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Resolve an interoperability issue with .NET when encrypting data in CBC mode. ```php CBC mode ``` -------------------------------- ### Find URIs of Reference Nodes Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Provide functionality to find the URIs of existing reference nodes using getRefNodeID() and getRefIDs(). ```php getRefNodeID() ``` ```php getRefIDs() ``` -------------------------------- ### XPath Support in Transformations Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Enable the use of XPath within transformations for more flexible data selection. ```php xpath support ``` -------------------------------- ### Overwrite URI Value Option Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Configure the addReference/List option to overwrite the URI value if it already exists within the document. Defaults to TRUE for backward compatibility. ```php overwrite ``` -------------------------------- ### Add Object for Enveloping Signatures Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Add the addObject method specifically for use with enveloping signatures. ```php addObject() ``` -------------------------------- ### Insert Signature Precisely Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Use the insertSignature method for precise control over signature insertion, merging functionality from appendSignature. ```php XMLSecurityDSig::insertSignature() ``` -------------------------------- ### Replace Deprecated Function Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Replace the deprecated 'split()' function with 'explode()' to ensure compatibility with newer PHP versions. ```php explode() ``` -------------------------------- ### Fix Canonicalization for Document Node Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Address canonicalization issues for the Document node when using PHP versions prior to 5.2. ```php PHP < 5.2 ``` -------------------------------- ### Append Signature to Node Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Use this parameter to append a signature to a specific node, particularly useful when dealing with inclusive canonicalization within namespaced subtrees. ```php $objDSig->sign($objKey, $appendToNode); ``` -------------------------------- ### Remove Closing PHP Tag Source: https://github.com/robrichards/xmlseclibs/blob/master/CHANGELOG.txt Remove the closing PHP tag to prevent extra whitespace characters from being output, which can cause issues. ```php ?> ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.