Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Pouliot <sebastien@ximian.com>2002-10-11 07:20:52 +0400
committerSebastien Pouliot <sebastien@ximian.com>2002-10-11 07:20:52 +0400
commit22fa9bf079cf1db58244ddbd0b49fe262061974d (patch)
tree507b664f21ff42490ff26ee79731e2c215c884ab /mcs/class/corlib/System.Security.Cryptography/AsymmetricAlgorithm.cs
parent91cb44526c3e44720e49c7f32e88ecc2aefd71e6 (diff)
2002-10-10 Sebastien Pouliot <spouliot@videotron.ca>
* AsymmetricAlgorithm.cs: Inherit from IDisposable, common support from XML import * DSA.cs: FromXmlString() keypair import, Create() using CryptoConfig * RSA.cs: FromXmlString() keypair import, Create() using CryptoConfig * DSACryptoServiceProvider.cs: Added Dispose() svn path=/trunk/mcs/; revision=8159
Diffstat (limited to 'mcs/class/corlib/System.Security.Cryptography/AsymmetricAlgorithm.cs')
-rwxr-xr-xmcs/class/corlib/System.Security.Cryptography/AsymmetricAlgorithm.cs56
1 files changed, 41 insertions, 15 deletions
diff --git a/mcs/class/corlib/System.Security.Cryptography/AsymmetricAlgorithm.cs b/mcs/class/corlib/System.Security.Cryptography/AsymmetricAlgorithm.cs
index 7910e6e8b8c..651906bbf8d 100755
--- a/mcs/class/corlib/System.Security.Cryptography/AsymmetricAlgorithm.cs
+++ b/mcs/class/corlib/System.Security.Cryptography/AsymmetricAlgorithm.cs
@@ -1,29 +1,32 @@
//
-// System.Security.Cryptography AsymmetricAlgorithm Class implementation
+// 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 System.Xml;
namespace System.Security.Cryptography {
-
+
/// <summary>
/// Abstract base class for all cryptographic asymmetric algorithms.
/// Available algorithms include:
/// RSA, DSA
/// </summary>
- public abstract class AsymmetricAlgorithm {
+ 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.
/// <summary>
/// Called from constructor of derived class.
/// </summary>
- protected AsymmetricAlgorithm () {
- throw new CryptographicException();
- }
+ protected AsymmetricAlgorithm () {}
/// <summary>
/// Gets the key exchange algorithm
@@ -59,6 +62,27 @@ namespace System.Security.Cryptography {
/// </summary>
public abstract string SignatureAlgorithm {get;}
+ void System.IDisposable.Dispose()
+ {
+ }
+
+ public void Clear()
+ {
+// Dispose();
+ }
+
+ protected abstract void Dispose (bool disposing);
+
+ // helper function for FromXmlString (used in RSA and DSA)
+ protected byte[] GetElement (XmlDocument xml, string tag)
+ {
+ XmlNodeList xnl = xml.GetElementsByTagName (tag);
+ if (xnl.Count > 0)
+ return Convert.FromBase64String (xnl[0].InnerText);
+ else
+ return null;
+ }
+
/// <summary>
/// Reconstructs the AsymmetricAlgorithm Object from an XML-string
/// </summary>
@@ -69,7 +93,8 @@ namespace System.Security.Cryptography {
/// </summary>
public abstract string ToXmlString(bool includePrivateParameters);
- private bool IsLegalKeySize(KeySizes[] LegalKeys, int Size) {
+ private bool IsLegalKeySize(KeySizes[] LegalKeys, int Size)
+ {
foreach (KeySizes LegalKeySize in LegalKeys) {
for (int i=LegalKeySize.MinSize; i<=LegalKeySize.MaxSize; i+=LegalKeySize.SkipSize) {
if (i == Size)
@@ -83,25 +108,26 @@ namespace System.Security.Cryptography {
/// Checks wether the given keyLength is valid for the current algorithm
/// </summary>
/// <param name="bitLength">the given keyLength</param>
- public bool ValidKeySize(int bitLength) {
+ public bool ValidKeySize(int bitLength)
+ {
return IsLegalKeySize(LegalKeySizesValue, bitLength);
}
/// <summary>
/// Creates the default implementation of the default asymmetric algorithm (RSA).
/// </summary>
- public static AsymmetricAlgorithm Create () {
- return RSA.Create();
+ public static AsymmetricAlgorithm Create ()
+ {
+ return Create ("System.Security.Cryptography.AsymmetricAlgorithm");
}
/// <summary>
/// Creates a specific implementation of the given asymmetric algorithm.
/// </summary>
- /// <param name="algName">the given algorithm</param>
- [MonoTODO]
- public static AsymmetricAlgorithm Create (string algName) {
- // TODO: use reflection to create a new instance of the given algorithm
- return null;
+ /// <param name="algo">Specifies which derived class to create</param>
+ public static AsymmetricAlgorithm Create (string algName)
+ {
+ return (AsymmetricAlgorithm) CryptoConfig.CreateFromName (algName);
}
}
}