盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

使用WSE 加密SOAP报文(6

时间:2025/1/4作者:未知来源:盾怪网教程人气:

[摘要]!myCert.SupportsDataEncryption) throw new ApplicationException("Service is not able to en...
!myCert.SupportsDataEncryption)

{

throw new ApplicationException("Service is not able to

encrypt the response");



return null;

}

else

{

//使用有效的证书来创建一个安全Token

X509SecurityToken myToken = new X509SecurityToken(myCert);

//WSE将使用这个标记来加密报文正文的

//WSE产生一个KeyInfo元素,用来请求客户端上曾用于给报文解密的证书



EncryptedData myEncData = new EncryptedData(myToken);

//将已加密数据元素添加到响应报文的SoapContext上

myContext.Security.Elements.Add(myEncData);



return myDoc;

}

基于前面的方法,WSE管道产生了下面的有相应Security头、密文和密钥信息的元素:

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<soap:Header>

<wsu:Timestamp

xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">

<wsu:Created>2003-02-11T01:34:01Z</wsu:Created>

<wsu:Expires>2003-02-11T01:39:01Z</wsu:Expires>

</wsu:Timestamp>

<wsse:Security soap:mustUnderstand="1"

xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">

<xenc:EncryptedKey

Type="http://www.w3.org/2001/04/xmlenc#EncryptedKey"

xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">

<xenc:EncryptionMethod

Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />

<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">

<wsse:SecurityTokenReference>

<wsse:KeyIdentifier ValueType="wsse:X509v3">

YmlKVwXYD8vuGuYliuIYdEAQQPw=

</wsse:KeyIdentifier>

</wsse:SecurityTokenReference>

</KeyInfo>

<xenc:CipherData>

<xenc:CipherValue>UJ64Addf3Fd59XsaQ=&Atilde;&#8218;&Acirc;…</xenc:CipherValue>

</xenc:CipherData>

<xenc:ReferenceList>

<xenc:DataReference URI=

"#EncryptedContent-608eef8b-4104-4469-95b6-7cb4703cfa03" />

</xenc:ReferenceList>

</xenc:EncryptedKey>

</wsse:Security>

</soap:Header>

<soap:Body xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility"

wsu:Id="Id-70179c5b-4975-4932-9ecd-a58feb34b0d3">

<xenc:EncryptedData

Id="EncryptedContent-608eef8b-4104-4469-95b6-7cb4703cfa03"

Type="http://www.w3.org/2001/04/xmlenc#Content"

xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">

<xenc:EncryptionMethod

Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />

<xenc:CipherData>

<xenc:CipherValue>

4o1b4befwBJu6tzuaygfrAaX0UGtaYKcw2klIbuZPjLi...z8i2ypHN4+w==

</xenc:CipherValue>

</xenc:CipherData>

</xenc:EncryptedData>

</soap:Body>

</soap:Envelope>

注意在这个已加密的报文里面,由非对称加密过的EncryptedKey元素包含了用于给报文正文加密的对称加密密钥。ReferenceList元素引用了报文正文的EncryptedData元素的Id属性。虽然我在我的例子中没这样做,标记这个消息以便能让容器验证发送者其实是个不错的想法。关于使用WSE来标记报文的详细信息,看WS-Security Authentication and Digital Signatures with Web Services Enhancements


关键词:运用WSE 加密SOAP报文(6




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版