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)
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"); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.