// // System.Security.Cryptography.AsymmetricAlgorithm Class implementation // // Authors: // Thomas Neidhart (tome@sbox.tugraz.at) // Sebastien Pouliot (spouliot@motus.com) // // Portions (C) 2002 Motus Technologies Inc. (http://www.motus.com) // using System; using Mono.Xml; namespace System.Security.Cryptography { // to import keypairs parameters using MiniParser internal class AsymmetricParameters : MiniParser.IReader { private string xml; private int pos; public AsymmetricParameters (string xml) { this.xml = xml; pos = 0; } public int Read () { try { return (int) xml [pos++]; } catch { return -1; } } } /// /// Abstract base class for all cryptographic asymmetric algorithms. /// Available algorithms include: /// RSA, DSA /// public abstract class AsymmetricAlgorithm : IDisposable { protected int KeySizeValue; // The size of the secret key used by the symmetric algorithm in bits. protected KeySizes[] LegalKeySizesValue; // Specifies the key sizes that are supported by the symmetric algorithm. /// /// Called from constructor of derived class. /// protected AsymmetricAlgorithm () {} /// /// Gets the key exchange algorithm /// public abstract string KeyExchangeAlgorithm {get;} /// /// Gets or sets the actual key size /// public virtual int KeySize { get { return this.KeySizeValue; } set { if (!KeySizes.IsLegalKeySize (this.LegalKeySizesValue, value)) throw new CryptographicException("key size not supported by algorithm"); this.KeySizeValue = value; } } /// /// Gets all legal key sizes /// public virtual KeySizes[] LegalKeySizes { get { return this.LegalKeySizesValue; } } /// /// Gets the signature algorithm /// public abstract string SignatureAlgorithm {get;} void IDisposable.Dispose () { Dispose (true); GC.SuppressFinalize (this); // Finalization is now unnecessary } public void Clear () { Dispose (false); } protected abstract void Dispose (bool disposing); /// /// Reconstructs the AsymmetricAlgorithm Object from an XML-string /// public abstract void FromXmlString (string xmlString); /// /// Returns an XML string representation the current AsymmetricAlgorithm object /// public abstract string ToXmlString (bool includePrivateParameters); /// /// Creates the default implementation of the default asymmetric algorithm (RSA). /// public static AsymmetricAlgorithm Create () { return Create ("System.Security.Cryptography.AsymmetricAlgorithm"); } /// /// Creates a specific implementation of the given asymmetric algorithm. /// /// Specifies which derived class to create public static AsymmetricAlgorithm Create (string algName) { return (AsymmetricAlgorithm) CryptoConfig.CreateFromName (algName); } } }