#xmlseclibs
xmlseclibs is a library written in PHP for working with XML Encryption and Signatures.
The author of xmlseclibs is Rob Richards.
Master is currently the only actively maintained branch.
- master/3.1: Added AES-GCM support requiring 7.1+
- 3.0: Removes mcrypt usage requiring 5.4+ (5.6.24+ recommended for security reasons)
- 2.0: Contains namespace support requiring 5.3+
- 1.4: Contains auto-loader support while also maintaining backwards compatiblity with the older 1.3 version using the xmlseclibs.php file. Supports PHP 5.2+
xmlseclibs requires PHP version 5.4 or greater. 5.6.24+ recommended for security reasons
Install with composer.phar.
php composer.phar require "robrichards/xmlseclibs"xmlseclibs is being used in many different software.
The example below shows basic usage of xmlseclibs, with a SHA-256 signature.
useRobRichards\XMLSecLibs\XMLSecurityDSig;
useRobRichards\XMLSecLibs\XMLSecurityKey;
// Load the XML to be signed$doc = newDOMDocument();
$doc->load('./path/to/file/tobesigned.xml');
// Create a new Security object $objDSig = newXMLSecurityDSig();
// 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 = newXMLSecurityKey(XMLSecurityKey::RSA_SHA256, array('type'=>'private'));
/*If key has a passphrase, set it using$objKey->passphrase = '<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');Mailing List: https://groups.google.com/forum/#!forum/xmlseclibs