This documentation is archived and is not being maintained.

XmlDsigBase64Transform Class

Represents the Base64 decoding transform as defined in Section 6.6.2 of the XMLDSIG specification.

System::Object
  System.Security.Cryptography.Xml::Transform
    System.Security.Cryptography.Xml::XmlDsigBase64Transform

Namespace:  System.Security.Cryptography.Xml
Assembly:  System.Security (in System.Security.dll)

[HostProtectionAttribute(SecurityAction::LinkDemand, MayLeakOnAbort = true)]
public ref class XmlDsigBase64Transform : public Transform

The XmlDsigBase64Transform type exposes the following members.

  NameDescription
Public methodXmlDsigBase64TransformInitializes a new instance of the XmlDsigBase64Transform class.
Top

  NameDescription
Public propertyAlgorithmGets or sets the Uniform Resource Identifier (URI) that identifies the algorithm performed by the current transform. (Inherited from Transform.)
Public propertyContextGets or sets an XmlElement object that represents the document context under which the current Transform object is running. (Inherited from Transform.)
Public propertyInputTypesGets an array of types that are valid inputs to the LoadInput method of the current XmlDsigBase64Transform object. (Overrides Transform::InputTypes.)
Public propertyOutputTypesGets an array of types that are possible outputs from the GetOutput methods of the current XmlDsigBase64Transform object. (Overrides Transform::OutputTypes.)
Public propertyPropagatedNamespacesGets or sets a Hashtable object that contains the namespaces that are propagated into the signature. (Inherited from Transform.)
Public propertyResolverSets the current XmlResolver object. (Inherited from Transform.)
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetDigestedOutputWhen overridden in a derived class, returns the digest associated with a Transform object. (Inherited from Transform.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Protected methodGetInnerXmlReturns an XML representation of the parameters of the XmlDsigBase64Transform object that are suitable to be included as subelements of an XMLDSIG <Transform> element. (Overrides Transform::GetInnerXml().)
Public methodGetOutput()Returns the output of the current XmlDsigBase64Transform object. (Overrides Transform::GetOutput().)
Public methodGetOutput(Type)Returns the output of the current XmlDsigBase64Transform object of type Stream. (Overrides Transform::GetOutput(Type).)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetXmlReturns the XML representation of the current Transform object. (Inherited from Transform.)
Public methodLoadInnerXmlParses the specified XmlNodeList object as transform-specific content of a <Transform> element; this method is not supported because the XmlDsigBase64Transform object has no inner XML elements. (Overrides Transform::LoadInnerXml(XmlNodeList).)
Public methodLoadInputLoads the specified input into the current XmlDsigBase64Transform object. (Overrides Transform::LoadInput(Object).)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Use the XmlDsigBase64Transform object when you need to sign the raw data associated with the encoded content of an element.

The Uniform Resource Identifier (URI) that describes the XmlDsigBase64Transform object is defined by the XmlDsigBase64TransformUrl field.

For more information about the Base64 decoding transform, see Section 6.6.2 of the XMLDSIG specification, which is available from the W3C at www.w3.org/TR/xmldsig-core/.

NoteNote

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: MayLeakOnAbort. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

The following code example demonstrates how to use members of the XmlDsigBase64Transform class.


#using <System.dll>
#using <System.Xml.dll>
#using <System.Security.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::Xml;

namespace CryptographyXmlDsigBase64Transform
{
    ref class Example
    {
    public:
        static void Produce()
        {

            // Encrypt an XML message
            EncryptXML(LoadXMLDoc());

            // Using XmlDsigBase64Transform resolving a Uri.
            Uri^ baseUri = gcnew Uri("http://www.microsoft.com");
            String^ relativeUri = "msdn";
            Uri^ absoluteUri = ResolveUris(baseUri, relativeUri);
            Console::WriteLine("This sample completed successfully; "
                "press Enter to exit.");
            Console::ReadLine();
        }


    private:

        // Encrypt the text in the specified XmlDocument.
        static void EncryptXML(XmlDocument^ xmlDoc)
        {

            XmlDsigBase64Transform^ xmlTransform = 
                gcnew XmlDsigBase64Transform;
            // Ensure the transform is using the proper algorithm.
            xmlTransform->Algorithm = 
                SignedXml::XmlDsigBase64TransformUrl;
            // Retrieve the XML representation of the current 
            // transform.
            XmlElement^ xmlInTransform = xmlTransform->GetXml();
            Console::WriteLine("Xml representation of the " 
                "current transform: ");
            Console::WriteLine(xmlInTransform->OuterXml);

            // Retrieve the valid input types for the current 
            // transform.
            array<Type^>^ validInTypes = xmlTransform->InputTypes;
            // Verify the xmlTransform can accept the XMLDocument
            // as an input type.
            for each (Type^ validInType in validInTypes)
            {
                if (validInType == xmlDoc->GetType())
                {

                    // Demonstrate loading the entire Xml Document.
                    xmlTransform->LoadInput(xmlDoc);
                    // This transform is created for demonstration 
                    // purposes.
                    XmlDsigBase64Transform^ secondTransform = 
                        gcnew XmlDsigBase64Transform;
                    String^ classDescription = 
                        secondTransform->ToString();
                    // This call does not perform as expected.
                    // LoadInnerXml is overridden by the 
                    // XmlDsigBase64Transform class, but is 
                    // stubbed out.
                    secondTransform->LoadInnerXml(
                        xmlDoc->SelectNodes("//."));
                    break;
                }

            }

            array<Type^>^ validOutTypes = xmlTransform->OutputTypes;
            for each (Type^ validOutType in validOutTypes)
            {
                if (validOutType == Stream::typeid)
                {
                    try
                    {

                        Type^ streamType = Stream::typeid;
                        CryptoStream^ outputStream = 
                            (CryptoStream^)(xmlTransform->GetOutput(
							streamType));
                        // Read the CryptoStream into a stream reader.
                        StreamReader^ streamReader = 
                            gcnew StreamReader(outputStream);

                        // Read the stream into a string.
                        String^ outputMessage = 
                            streamReader->ReadToEnd();

                        // Close the streams.
                        outputStream->Close();
                        streamReader->Close();

                        // Display to the console the Xml before and
                        // after encryption.
                        Console::WriteLine("Encoding the following "
                            "message: {0}", xmlDoc->InnerText);
                        Console::WriteLine("Message encoded: {0}", 
                            outputMessage);
                    }
                    catch (CryptographicException^ ex) 
                    {
                        Console::WriteLine("Cryptographic exception "
                            "caught: {0}", ex);
                    }

                    break;
                }
                else
                {

                    Object^ outputObject = xmlTransform->GetOutput();
                }

            }
        }


        // Create an XML document with Element and Text nodes.
        static XmlDocument^ LoadXMLDoc()
        {
            XmlDocument^ xmlDoc = gcnew XmlDocument;
            XmlNode^ mainNode = 
                xmlDoc->CreateNode(XmlNodeType::Element, 
                "ContosoMessages", "http://www.contoso.com");
            XmlNode^ textNode = xmlDoc->CreateTextNode("Some text "
                "to encode.");
            mainNode->AppendChild(textNode);
            xmlDoc->AppendChild(mainNode);
            Console::WriteLine("Created the following XML Document "
                "for transformation: ");
            Console::WriteLine(xmlDoc->InnerXml);
            return xmlDoc;
        }


        // Resolve the specified base and relative Uri's.
        static Uri^ ResolveUris(Uri^ baseUri, String^ relativeUri)
        {

            XmlUrlResolver^ xmlResolver = gcnew XmlUrlResolver;
            xmlResolver->Credentials = 
                System::Net::CredentialCache::DefaultCredentials;
            XmlDsigBase64Transform^ xmlTransform = 
                gcnew XmlDsigBase64Transform;
            xmlTransform->Resolver = xmlResolver;
            Uri^ absoluteUri = xmlResolver->ResolveUri(baseUri, 
                relativeUri);
            if (absoluteUri != nullptr)
            {
                Console::WriteLine("Resolved the base Uri and "
                    "relative Uri to the following:");
                Console::WriteLine(absoluteUri);
            }
            else
            {
                Console::WriteLine("Unable to resolve the base "
                    "Uri and relative Uri");
            }

            return absoluteUri;
        }

    };

}

int main()
{
    CryptographyXmlDsigBase64Transform::Example::Produce();
}

//
// This sample produces the following output:
//
// Created the following XML Document for transformation:
// <ContosoMessages xmlns="http://www.contoso.com">Some text to encode.
// </ContosoMessages>
// Xml representation of the current transform:
// <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#base64"
// xmlns="http://www.w3.org/2000/09/xmldsig#" />
// Encoding the following message: Some text to encode.
// Message encoded: Jmr^
// Resolved the base Uri and relative Uri to the following:
// http://www.microsoft.com/msdn
// This sample completed successfully; press Enter to exit.


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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