simplesamlphp / xmlseclibs
此包已被弃用,不再维护。未建议替代包。
PHP XML安全库
3.0.1
2017-08-31 09:27 UTC
Requires
- php: >= 5.4
Suggests
- ext-openssl: OpenSSL extension
This package is auto-updated.
Last update: 2021-01-06 15:26:58 UTC
README
#xmlseclibs
xmlseclibs 是一个用 PHP 编写的库,用于处理 XML 加密和签名。
xmlseclibs 的作者是 Rob Richards。
分支
当前只有 master 分支正在积极维护。
- master/3.1: 添加了 AES-GCM 支持,需要 7.1+
- 3.0: 移除了对 mcrypt 的使用,需要 5.4+(出于安全原因,建议使用 5.6.24+)
- 2.0: 包含命名空间支持,需要 5.3+
- 1.4: 包含自动加载支持,同时保持与较旧的 1.3 版本(使用 xmlseclibs.php 文件)的后向兼容性。支持 PHP 5.2+
要求
xmlseclibs 需要 PHP 版本 5.4 或更高版本。出于安全原因,建议使用 5.6.24+
如何安装
使用 composer.phar
进行安装。
php composer.phar require "robrichards/xmlseclibs"
使用场景
xmlseclibs 被许多不同的软件使用。
基本使用
以下示例展示了 xmlseclibs 的基本使用,使用 SHA-256 签名。
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 = '<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');