WSE 3.0加密签名c#

时间:2015-09-13 05:15:24

标签: c# xml encryption soap digital-signature

我在C#项目中使用soap对象

我需要发送安全请求,签名并加密,现在我有了这段代码

public void request() {
        Uri destinationUri = new Uri("SomePath");

        EndpointReference destination = new EndpointReference(destinationUri);
        SoapSender sender = new SoapSender(destination);

        SoapEnvelope envelope = new SoapEnvelope();
        envelope.Context.Addressing.Action = new Action("http://www.some\blabla");                        

        XmlElement xe = envelope.CreateElement("demo");
        envelope.Body.AppendChild(xe);


        X509Certificate2 cert = new X509Certificate2(@"C:\certi.p12", "blabla", X509KeyStorageFlags.DefaultKeySet);

        X509SecurityToken myToken = new X509SecurityToken(cert);           

        MessageSignature sig = new MessageSignature(myToken);
        sig.SignatureOptions = SignatureOptions.IncludeTimestamp | SignatureOptions.IncludeSoapBody;

        EncryptedData myEncData = new EncryptedData(myToken); 

        envelope.Context.Security.Elements.Add(sig);

        envelope.Context.Security.Elements.Add(myEncData);

        try
        {
            sender.Send(envelope);
        }
        catch (Exception ex) { }
  }

并且有效,但它只加密身体而不是签名

我还必须加密签名

目前它产生了这个请求

<soap:Envelope>
    <soap:Header>
        <wsse:Security soap:mustUnderstand="1">
            <wsu:Timestamp wsu:Id="Timestamp-d8175ff3-5253-447e-b2cb-59766874db62">
                <wsu:Created>2015-09-13T05:09:12Z</wsu:Created>
                <wsu:Expires>2015-09-13T05:14:12Z</wsu:Expires>
            </wsu:Timestamp>
            <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
            </Signature>
        </wsse:Security>
    </soap:Header>
    <soap:Body>
        <xenc:EncryptedData>
        </xenc:EncryptedData>
    </soap:Body>
</soap:Envelope>

0 个答案:

没有答案