【问题标题】:xmldsig php do not add signing info in XMLxmldsig php 不在 XML 中添加签名信息
【发布时间】:2015-07-22 05:50:40
【问题描述】:

对不起我的英语:)。 我需要像这样在 XML 中编写签名块:

ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#gost34310-gost34311"/>
<ds:Reference>
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#gost34311"/>
<ds:DigestValue>drvEZVSz3nSXHVI6+iRSDXZDGud9Ay56LLfMkpQkRp4=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>/4ASSFXCsdsdMuwM9kw0riDbhhtLR/+UKZKNO51HbACu5DM
SLmmAmp5FwFHdsGtBQ==</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>

我在 GIT 中找到了这个:https://github.com/Maks3w/xmldsig 我的代码是:

        $data = new DOMDocument();
        $data->load(__DIR__ . '/newdata.xml');
        $xmlTool = new FR3D\XmlDSig\Adapter\XmlseclibsAdapter();
        $xmlTool->setPrivateKey(file_get_contents('C:\xampp\htdocs\EgovPayments\private1.pem'));
        $publicKey=$xmlTool->getPublicKey();
        //echo 'public key is:'.$publicKey;
        $xmlTool->setPublicKey($publicKey);
        $xmlTool->addTransform(FR3D\XmlDSig\Adapter\AdapterInterface::ENVELOPED);
        $xmlTool->setCanonicalMethod('http://www.w3.org/2001/10/xml-exc-c14n#');
        $xmlTool->sign($data);
        $data->saveXML();

但是 newdata.xml 中没有任何变化,它如何与 PHP 中的 xmldsig 一起工作? 谢谢

【问题讨论】:

  • 那ghost呢,怎么用ghost的方法做签名呢?
  • w3.org/2001/04/xmldsig-more#gost34310-gost34311">
  • 对此也感兴趣。

标签: php xml xml-signature


【解决方案1】:

函数 DOMDocument::saveXML() 返回字符串。不是更新文件。
http://php.net/manual/en/domdocument.savexml.php

【讨论】:

    【解决方案2】:

    我遇到了同样的问题 - 但在 seclib 中找到以下函数“insertSignature”。

    如果您使用适配器,则将以下行添加到验证函数的末尾:

    $objXMLSecDSig->insertSignature($data->getElementsByTagName("Security")->item(0));
    

    【讨论】:

      猜你喜欢
      • 2022-09-27
      • 1970-01-01
      • 2015-11-18
      • 2019-10-20
      • 2022-08-06
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多