AsymmetricAlgorithm.FromXmlString(String) Method

Definition

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

public virtual void FromXmlString (string xmlString);
public abstract void FromXmlString (string xmlString);

Parameters

xmlString
String

The XML string to use to reconstruct the AsymmetricAlgorithm object.

Examples

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:
//      <ProviderName></ProviderName>
//      <KeyContainerName></KeyContainerName>
//      <KeyNumber></KeyNumber>
//      <ProviderType></ProviderType>
public override void FromXmlString(string xmlString)
{
    if (xmlString != null)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xmlString);
        XmlNode firstNode = doc.FirstChild;
        XmlNodeList nodeList;

        // Assemble parameters from values in each XML element.
        cspParameters = new CspParameters();

        // KeyContainerName is optional.
        nodeList = doc.GetElementsByTagName("KeyContainerName");
        string keyName = nodeList.Item(0).InnerText;
        if (keyName != null) 
        {
            cspParameters.KeyContainerName = keyName;
        }

        // KeyNumber is optional.
        nodeList = doc.GetElementsByTagName("KeyNumber");
        string keyNumber = nodeList.Item(0).InnerText;
        if (keyNumber != null) 
        {
            cspParameters.KeyNumber = Int32.Parse(keyNumber);
        }

        // ProviderName is optional.
        nodeList = doc.GetElementsByTagName("ProviderName");
        string providerName = nodeList.Item(0).InnerText;
        if (providerName != null) 
        {
            cspParameters.ProviderName = providerName;
        }

        // ProviderType is optional.
        nodeList = doc.GetElementsByTagName("ProviderType");
        string providerType = nodeList.Item(0).InnerText;
        if (providerType != null) 
        {
            cspParameters.ProviderType = Int32.Parse(providerType);
        }
    }
    else
    {
        throw new ArgumentNullException("xmlString");
    }
}

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also