首页 > 解决方案 > 肥皂节点模块数字签名

问题描述

如果 npm 模块“soap”支持数字签名,请告诉我。我需要生成如下所示的肥皂标题

<s:Header>
    <Action s:mustUnderstand="1"
        xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://example.com
    </Action>
    <Signature
        xmlns="http://www.w3.org/2000/09/xmldsig#">
        <SignedInfo>
            <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
            <Reference URI="#Body">
                <Transforms>
                    <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                </Transforms>
                <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                <DigestValue>ABCDE=</DigestValue>
            </Reference>
        </SignedInfo>
        <SignatureValue>jx5IYbz8mDxTXgV6UhhV/</SignatureValue>
        <KeyInfo>
            <X509Data>
                <X509IssuerSerial>
                    <X509IssuerName>C</X509IssuerName>
                    <X509SerialNumber>12345</X509SerialNumber>
                </X509IssuerSerial>
                <X509Certificate>certificate</X509Certificate>
            </X509Data>
        </KeyInfo>
    </Signature>
</s:Header>

标签: npmsoapnode-soap

解决方案


答案是肯定的。节点模块'soap'支持您的soap请求按照您的要求进行数字签名。这属于“WS-SECURITY”。您需要有一个私钥和一个公钥来执行 ws-security。

我正在提供一个示例片段,希望这会有所帮助

soap.createClient(url,async function(err,client){
        if(!err){
            var privateKey = 'Read your private key file (.pem file)'
            var password = 'your signer password'; 
            var wsSecurity = new soap.WSSecurityCert(privateKey['your attribute'].key, privateKey['your attribute'].cert, password, 'utf8');
            client.setSecurity(wsSecurity);
          
            client.<your_function_here>({your parameters},async function(er,result){
                console.log(client.lastRequest);// This will print the request that is been called.
                if(er){
                    console.log("API RESPONSE ERROR: "+JSON.stringify(er.message));
                }else{
                    console.log(result);
                }
            })
        }
    })

请参考此链接:https ://www.npmjs.com/package/soap#wssecuritycert


推荐阅读