Export (0) Print
Expand All

AsymmetricAlgorithm.FromXmlString Method

When overridden in a derived class, reconstructs an AsymmetricAlgorithm object from an XML string.

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

public:
virtual void FromXmlString (
	String^ xmlString
) abstract
public abstract void FromXmlString (
	String xmlString
)
public abstract function FromXmlString (
	xmlString : String
)
Not applicable.

Parameters

xmlString

The XML string to use to reconstruct the AsymmetricAlgorithm object.

The following code example demonstrates how to implement the FromXmlString method to parse the specified XML string to populate the current CspParameters object. This code example is part of a larger example provided for the AsymmetricAlgorithm class.

    // Expected XML schema:
    //  <CustomCryptoKeyValue>
    //      <ProviderName></ProviderName>
    //      <KeyContainerName></KeyContainerName>
    //      <KeyNumber></KeyNumber>
    //      <ProviderType></ProviderType>
    //  </CustomCryptoKeyValue>
public:
    virtual void FromXmlString(String^ xmlString) override 
    {
        if (xmlString != nullptr)
        {
            XmlDocument^ document = gcnew XmlDocument();
            document->LoadXml(xmlString);
            XmlNode^ firstNode = document->FirstChild;
            XmlNodeList^ nodeList;

            // Assemble parameters from values in each XML element.
            cryptoServiceParameters = gcnew CspParameters();

            // KeyContainerName is optional.
            nodeList = 
                document->GetElementsByTagName("KeyContainerName");
            if (nodeList->Count > 0)
            {
                cryptoServiceParameters->KeyContainerName =
                    nodeList->Item(0)->InnerText;
            }

            // KeyNumber is optional.
            nodeList = document->GetElementsByTagName("KeyNumber");
            if (nodeList->Count > 0)
            {
                cryptoServiceParameters->KeyNumber =
                    Int32::Parse(nodeList->Item(0)->InnerText);
            }

            // ProviderName is optional.
            nodeList = document->GetElementsByTagName("ProviderName");
            if (nodeList->Count > 0)
            {
                cryptoServiceParameters->ProviderName =
                    nodeList->Item(0)->InnerText;
            }

            // ProviderType is optional.
            nodeList = document->GetElementsByTagName("ProviderType");
            if (nodeList->Count > 0)
            {
                cryptoServiceParameters->ProviderType =
                    Int32::Parse(nodeList->Item(0)->InnerText);
            }
        }
        else
        {
            throw gcnew ArgumentNullException("xmlString");
        }
    }

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft