Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
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 abstract void FromXmlString (
	string xmlString
)
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 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");
    }
}

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