gpt4 book ai didi

php - 有没有 xmlseclibs 的文档?

转载 作者:可可西里 更新时间:2023-10-31 23:05:14 26 4
gpt4 key购买 nike

我已经签署了 XML,但我不知道如何在签名中包含 KeyValue 元素。拥有一些文档会节省很多时间。

下面的代码(如果您有兴趣的话)是我到目前为止使用 xmlseclibs 所做的:

<?php
require('xmlseclibs.php');

XML 字符串

$getToken = '<getToken>
<item>
<Semilla>Random string</Semilla>
</item>
</getToken>';

创建 XML 对象(签名)

$getToken_DOMDocument = new DOMDocument(); 
$getToken_DOMDocument -> loadXml($getToken);

使用 xmlseclibs 创建签名对象

$getToken_XMLSecurityDSig = new XMLSecurityDSig(); 
$getToken_XMLSecurityDSig -> setCanonicalMethod(XMLSecurityDSig::C14N);

试图关闭不起作用的 ds: 前缀

$options['prefix'] = '';
$options['prefix_ns'] = '';
$options['force_uri'] = TRUE;
$options['id_name'] = 'ID';

$getToken_XMLSecurityDSig -> addReference($getToken_DOMDocument, XMLSecurityDSig::SHA1, array('http://www.w3.org/2000/09/xmldsig#enveloped-signature', 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'), $options);

访问必要的关键数据

$XMLSecurityKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private')); 
$XMLSecurityKey -> loadKey('../../DTE/certificado/firma/certificado.pem', TRUE);
/* if key has Passphrase, set it using $objKey -> passphrase = <passphrase> */

签署 XML 对象

$getToken_XMLSecurityDSig -> sign($XMLSecurityKey); 

添加公钥

$getToken_XMLSecurityDSig -> add509Cert(file_get_contents('../../DTE/certificado/firma/certificado.pem')); 

将封装的签名附加到 XML 对象

$getToken_XMLSecurityDSig -> appendSignature($getToken_DOMDocument -> documentElement); 

将签名的 XML 代码保存到文件

$getToken_DOMDocument -> save('sign-basic-test.xml'); 
?>

此外还想从这个库中得到:

  1. 了解官方和可信赖的存储库以确保库未损坏。
  2. 关闭“ds:”前缀(因为我生成的 XML 示例和文档都不包含此类前缀)。
  3. 在 Base64 类型值中每隔 X 个字符换行。
  4. 完整缩进(否则根本没有)。

我从 enter link description here 得到了库

提前致谢。

最佳答案

关于php - 有没有 xmlseclibs 的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24922384/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com