cabreran/xmlseclibs
最新稳定版本:v3.1.0
Composer 安装命令:
composer require cabreran/xmlseclibs
包简介
A PHP library for XML Security
README 文档
README
#xmlseclibs
xmlseclibs is a library written in PHP for working with XML Encryption and Signatures.
Requirements
xmlseclibs requires PHP version 7.1 or greater.
How to Install
Install with composer.phar.
php composer.phar require "cabreran/xmlseclibs"
Use cases
xmlseclibs is being used in many different software.
Basic usage
The example below shows basic usage of xmlseclibs, with a SHA-256 signature.
use Cabreran\XMLSecLibs\XMLSecurityDSig; use Cabreran\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');
统计信息
- 总下载量: 13.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2020-07-17