EncryptedData Class

Represents the encrypted data.

Namespace: Microsoft.Web.Services2.Security
Assembly: Microsoft.Web.Services2 (in microsoft.web.services2.dll)

Usage

'Usage
Dim token As SecurityToken
Dim encryptedData1 As New EncryptedData(token)

Syntax

'Declaration
NotInheritable Public Class EncryptedData
    Implements ISecurityElement, IXmlElement
public sealed class EncryptedData : ISecurityElement, IXmlElement
public sealed ref class EncryptedData : public ISecurityElement, IXmlElement
public final class EncryptedData implements ISecurityElement, IXmlElement
public class EncryptedData implements ISecurityElement, , IXmlElement

Example

The following code example encrypts a SOAP message using an X.509 certificate. The GetSecurityTokenmethod retrieves an X.509 certificate from the certificate store. To view the code for the GetSecurittyToken method, see How to: Encrypt a SOAP Message Using an X.509 Certificate.

        ' Gets the SoapContext for the SOAP request that is to be sent
        ' to the XML Web service.
        Dim svc As New Service1Wse
        Dim requestContext As SoapContext = svc.RequestSoapContext

        ' Gets an X.509 certificate for encrypting the SOAP message.
        Dim encryptionToken As X509SecurityToken = GetSecurityToken(False)

        If encryptionToken Is Nothing Then
            Return
        End If
        ' Adds the X.509 certificate to the WS-Security header.
        requestContext.Security.Tokens.Add(encryptionToken)

        ' Encrypts the SOAP message using the X.509 certificate.
        requestContext.Security.Elements.Add(New EncryptedData(encryptionToken))

        ' Sets the TTL to one minute.
        requestContext.Security.Timestamp.TtlInSeconds = 60

        ' Makes the SOAP request to the XML Web service.
        textBoxResult.Text = svc.AddNumbers(a, b).ToString()
    Catch ex As Exception
        MessageBox.Show(ex.ToString())
    End Try
End Sub 'Encrypt 
    // Gets the SoapContext for the SOAP request that is to be sent
    // to the XML Web service.
    Service1Wse svc = new Service1Wse();
    SoapContext requestContext = svc.RequestSoapContext;

    // Gets an X.509 certificate for encrypting the SOAP message.
    X509SecurityToken encryptionToken = GetSecurityToken(false);
    if (encryptionToken == null) 
    {
        return;
    }
    // Adds the X.509 certificate to the WS-Security header.
    requestContext.Security.Tokens.Add(encryptionToken);

    // Encrypts the SOAP message using the X.509 certificate.
    requestContext.Security.Elements.Add(new EncryptedData(encryptionToken));

    // Sets the TTL to one minute.
    requestContext.Security.Timestamp.TtlInSeconds = 60;

    // Makes the SOAP request to the XML Web service.
    textBoxResult.Text = svc.AddNumbers(a,b).ToString() ;
}
catch (Exception ex) 
{
    MessageBox.Show(ex.ToString());
}

Inheritance Hierarchy

System.Object
  Microsoft.Web.Services2.Security.EncryptedData

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Longhorn, and Windows 2000

Target Platforms

Windows 2000, Windows 2000 Server, Windows 2000 Advanced Server, Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Longhorn, Pocket PC, Windows CE, Smart Phone

See Also

Reference

Microsoft.Web.Services2.Security Namespace

Other Resources

EncryptedData Members