kduma / signed-document
XML 文档签名器
v0.3.0
2021-01-27 19:33 UTC
Requires
- php: ^7.4|^8.0
- ext-dom: *
- paragonie/halite: ^4.6
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-08-28 03:54:46 UTC
README
PHP 实现数字文档签名。
安装
您可以通过 composer 安装此包。
composer require kduma/signed-document
使用
创建和签名文档
$signer = new \Kduma\SignedDocument\DocumentSigner( \ParagonIE\Halite\KeyFactory::generateSignatureKeyPair()->getSecretKey() ); $document_1 = \Kduma\SignedDocument\Document::make("Some Content", 'test-document'); $document_1->addSignature($signer->sign($document_1, 'ceo')); $document_2 = \Kduma\SignedDocument\Document::make("Some Other Content", 'other-document'); $document_2->addSignature($signer->sign($document_2, 'ceo')); $collection = new \Kduma\SignedDocument\DocumentCollection(); $collection->addDocument($document_1); $collection->addDocument($document_2); echo $collection->getXml();
示例输出
<?xml version="1.0" encoding="UTF-8"?> <documents xmlns="https://opensource.duma.sh/xml/signed-document" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://opensource.duma.sh/xml/signed-document https://github.com/kduma-OSS/PHP-signed-document/raw/master/schema/signed-document.xsd"> <document> <content encoding="raw" sha256="950f1fb144716a62ed1f19f04d8a9ddcc35869d278641fd4f724012b3bbf7d70"><![CDATA[Some Content]]></content> <signature id="ceo" public-key="314004003d9fb8394a38d3c116b7f8042ca626d71594ce476a0479c0d2e51d9b7ba087845d34d44e054ae321595d6da514b71bec6ee3e0e1712d475bcddcddbfdeaa5aa59fb4b9590387f9bcd54ccffc30b48040b37cfc93548d50ce1353a19ed157d6a2">09ef8a4aca1ed3faf0886351f54fd6469b60fee91f41ad27176b77cb6a287f4850cd89661cac0f02d3cdbc8821c9defb0d337c368583241f20d208d821977d09</signature> </document> <document> <content encoding="raw" sha256="0f897b0422d2307fe88d8dda7b6996c4a264b468f5bc6be383b4623c2734f840"><![CDATA[Some Other Content]]></content> <signature id="ceo" public-key="314004003d9fb8394a38d3c116b7f8042ca626d71594ce476a0479c0d2e51d9b7ba087845d34d44e054ae321595d6da514b71bec6ee3e0e1712d475bcddcddbfdeaa5aa59fb4b9590387f9bcd54ccffc30b48040b37cfc93548d50ce1353a19ed157d6a2">af8dcdcb2f2644edd633bf288df516c27fe25904e314cc71a9e26c7121376b10fff83615d4c6ac6df2f7512ac23efaa0cb55235c941b3c9653705741e7879808</signature> </document> </documents>
验证
$signer = new \Kduma\SignedDocument\DocumentValidator(); $collection = \Kduma\SignedDocument\DocumentCollection::fromXml('<?xml version="1.0" encoding="UTF-8"?><documents xmlns="https://opensource.duma.sh/xml/signed-document"...'); var_dump($signer->validateCollection($collection));
测试
composer test
变更日志
请参阅 CHANGELOG 获取更多最近更改的信息。
贡献
请参阅 CONTRIBUTING 获取详细信息。
安全
如果您发现任何安全相关的问题,请通过电子邮件 oss@krystian.duma.sh 报告,而不是使用问题跟踪器。
鸣谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 获取更多信息。