FromXmlString Method
Collapse the table of content
Expand the table of content

AsymmetricAlgorithm.FromXmlString Method (String)

 

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

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

public virtual void FromXmlString(
	string xmlString
)

Parameters

xmlString
Type: System.String

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 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");
    }
}

.NET Framework
Available since 1.1
Windows Phone Silverlight
Available since 7.1
Return to top
Show:
© 2016 Microsoft