ninosimeon/ xmlseclibs_sunat
一个用于XML安全的PHP库
3.0.1
2017-03-22 05:38 UTC
Requires
- php: >= 5.3
Suggests
- ext-mcrypt: MCrypt extension
- ext-openssl: OpenSSL extension
This package is auto-updated.
Last update: 2024-09-06 10:08:29 UTC
README
#xmlseclibs_sunat
xmlseclibs_sunat 是一个用PHP编写的用于XML电子签名的库。
xmlseclibs的作者是Rob Richards。官方仓库:https://github.com/robrichards/xmlseclibs
要求
xmlseclibs_sunat 需要 PHP 5.3 或更高版本。
如何安装
使用 composer.phar
安装。
php composer.phar require "ninosimeon/xmlseclibs_sunat"
使用场景
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('ds', $signId); // 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')); // Load the private key $objKey->loadKey('./path/to/privatekey.pem', TRUE); /* If key has a passphrase, set it using $objKey->passphrase = '<passphrase>'; */ // 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');