metalback/xmldsig
Composer 安装命令:
composer require metalback/xmldsig
包简介
Fork of Selective\XmlDSig for Sign XML Documents with Digital Signatures
关键字:
README 文档
README
Features
- Sign XML Documents with Digital Signatures (XMLDSIG)
- Verify the Digital Signatures of XML Documents
Requirements
- PHP 7.2+ or 8.0+
- The openssl extension
- A X.509 digital certificate
Installation
composer require selective/xmldsig
Usage
Sign XML Document with Digital Signature
Input file: example.xml
<?xml version="1.0"?> <root> <creditcard> <number>19834209</number> <expiry>02/02/2025</expiry> </creditcard> </root>
use Selective\XmlDSig\DigestAlgorithmType; use Selective\XmlDSig\XmlSigner; $xmlSigner = new XmlSigner(); $xmlSigner->loadPfxFile('filename.pfx', 'password'); // or load pfx from a string //$xmlSigner->loadPfx('pfx content', 'password'); // or load a PEM file //$xmlSigner->loadPrivateKeyFile('filename.pem', 'password'); // or load a PEM private key from a string //$xmlSigner->loadPrivateKey('private key content', 'password'); // Optional: Set reference URI $xmlSigner->setReferenceUri(''); $xmlSigner->signXmlFile('example.xml', 'signed-example.xml', DigestAlgorithmType::SHA512);
Output file: signed-example.xml
<?xml version="1.0"?> <root> <creditcard> <number>19834209</number> <expiry>02/02/2025</expiry> </creditcard> <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> <SignedInfo> <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/> <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"/> <Reference URI=""> <Transforms> <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/> </Transforms> <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha512"/> <DigestValue>Base64EncodedValue==</DigestValue> </Reference> </SignedInfo> <SignatureValue>AnotherBase64EncodedValue===</SignatureValue> </Signature> </root>
Verify the Digital Signatures of XML Documents
use Selective\XmlDSig\XmlSignatureValidator; // Create a validator instance $signatureValidator = new XmlSignatureValidator();
// Load a PFX file $signatureValidator->loadPfxFile('filename.pfx', 'password'); // or load just a public key file from a string $signatureValidator->loadPfx('public key content', 'password'); // or load a public key file (without password) $signatureValidator->loadPublicKeyFile('cacert.pem'); // or load the public key from a string (without password) $signatureValidator->loadPublicKey('public key content');
// Verify a XML file $isValid = $signatureValidator->verifyXmlFile('signed-example.xml'); // or verify XML from a string $isValid = $signatureValidator->verifyXml('xml content'); if ($isValid === true) { echo 'The XML signature is valid.'; } else { echo 'The XML signature is not valid.'; }
Online XML Digital Signature Verifier
Try these excellent online tools to verify XML signatures:
Similar libraries
License
The MIT License (MIT). Please see License File for more information.
metalback/xmldsig 适用场景与选型建议
metalback/xmldsig 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 11 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「xml」 「xmldsig」 「verify」 「signatures」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 metalback/xmldsig 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 metalback/xmldsig 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 metalback/xmldsig 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides a Facade to help validate and verify email addresses
Load DOM document safety
A PHP library for XML Security
Added a method to Laravel response for handling xml response and also converting Eloquent return to XML.
A PHP library for XML Security
Uses reflection to map XML to PHP objects.
统计信息
- 总下载量: 29
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-11-16