Use WSE to Encrypt SOAP packets (6

Source: Internet
Author: User
Tags asymmetric encryption

Encrypt messages sent externally
I have modified the previous GetXmlDocument method so that it can use the X.509-based asymmetric encryption technology implemented by WSE. The FindCertificateBySubjectString method can be used to receive public backups of client certificates, a client certificate from the personal storage room of the Local Machine Account. This certificate is then used to create a new X.509 Security Token, which will be added to the SoapContext Security Token set of the Response Message. In addition, for the namespace referenced in the symmetric encryption example, you should add a using directive to reference a Microsoft. WebServices. Security. X509 namespace. The code for the GetXmlDocument method is as follows:
// Create a simple XML document for returning
XmlDocument myDoc = new XmlDocument ();
MyDoc. InnerXml =
"<EncryptedResponse> This is sensitive data. </EncryptedResponse> ";
"<EncryptedResponse> sensitive data. </EncryptedResponse> ";

// Obtain the SoapContext of the Response Message
SoapContext myContext = HttpSoapContext. ResponseContext;

// Open and read the personal certificate storage room of the Local Machine Account
X509CertificateStore myStore =
X509CertificateStore. LocalMachineStore (
X509CertificateStore. MyStore );
MyStore. OpenRead ();

// Search for all certificates named "my certificates" and add all matching certificates to the certificate set
X509CertificateCollection myCerts =
MyStore. FindCertificateBySubjectString ("My Certificate ");
X509Certificate myCert = null;

// Search for the first certificate in the Set
If (myCerts. Count> 0)
{
MyCert = myCerts [0];
}

// Confirm that we have a certificate that can be used for encryption
If (myCert = null |! MyCert. SupportsDataEncryption)
{
Throw new ApplicationException ("Service is not able

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.