首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在php中签名SOAP消息

如何在php中签名SOAP消息
EN

Stack Overflow用户
提问于 2016-04-21 15:17:52
回答 1查看 3.3K关注 0票数 1

我正在使用php (yii2),我想实现与服务器的SOAP通信。我有下面的SOAP指南:

客户的系统使用客户的私钥来发出数字签名。应用程序请求(ApplicationRequest)和SOAP消息都必须在WSC中单独签名。签名使用私钥执行。签名系统必须包括签名和证书。此证书包含与签名中使用的私钥相对应的公钥。接收方使用公钥来验证签名。

以及:

下一步:用发件人证书的私钥对整个SOAP消息进行数字签名(分离型XML数字签名),并将签名放入SOAP-头中

所以,我有自己的private.keypublic.keycertificate.cer

我的代码看起来像

代码语言:javascript
运行
复制
    $client = new SoapClient($wdsl, ['trace' => true]);
    $arguments = ['DownloadFileListRequest' => $dflr];
    $appResponse = $client->__call('downloadFileList', $arguments);

但我得到了预期的错误:

SOAP signature error

我要做什么,怎么签这个肥皂?

EN

回答 1

Stack Overflow用户

发布于 2017-03-12 11:30:41

XMLSecurityDSig帮助(https://github.com/robrichards/xmlseclibs)

代码语言:javascript
运行
复制
$dom = new DOMDocument('1.0', 'UTF-8');
$ar = $dom->createElementNS('http://bxd.fi/xmldata/', 'ApplicationRequest');
$dom->appendChild($ar);
$ar->appendChild($dom->createElement('CustomerId', $this->userID));
...
$ar->appendChild($dom->createElement('Content', $contentBase64));

$objDSig = new XMLSecurityDSig();
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
$objDSig->addReference(
            $dom,
            XMLSecurityDSig::SHA256,
            ['http://www.w3.org/2000/09/xmldsig#enveloped-signature'],
            ['force_uri' => true]
        );
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, ['type'=>'private']);
$objKey->loadKey($this->privateKeyPath, true);
$objDSig->sign($objKey);
$objDSig->add509Cert(base64_encode(file_get_contents($this->certificatePath)), false);
$objDSig->appendSignature($dom->documentElement);

$xmlRaw = $dom->saveXML();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36773869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档