//
// Authors:
// Thomas Neidhart (tome@sbox.tugraz.at)
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot (sebastien@ximian.com)
//
// Portions (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004-2005, 2008 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
+using System.Globalization;
+using System.Runtime.InteropServices;
namespace System.Security.Cryptography {
- /// <summary>
- /// Abstract base class for all cryptographic asymmetric algorithms.
- /// Available algorithms include:
- /// RSA, DSA
- /// </summary>
- public abstract class AsymmetricAlgorithm : IDisposable {
+ [ComVisible (true)]
+ 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.
+ protected int KeySizeValue;
+ protected KeySizes[] LegalKeySizesValue;
- /// <summary>
- /// Called from constructor of derived class.
- /// </summary>
- protected AsymmetricAlgorithm () {}
+ protected AsymmetricAlgorithm ()
+ {
+ }
- /// <summary>
- /// Gets the key exchange algorithm
- /// </summary>
- public abstract string KeyExchangeAlgorithm {get;}
+ public abstract string KeyExchangeAlgorithm {
+ get;
+ }
- /// <summary>
- /// Gets or sets the actual key size
- /// </summary>
public virtual int KeySize {
get { return this.KeySizeValue; }
set {
if (!KeySizes.IsLegalKeySize (this.LegalKeySizesValue, value))
- throw new CryptographicException("key size not supported by algorithm");
+ throw new CryptographicException (Locale.GetText ("Key size not supported by algorithm."));
this.KeySizeValue = value;
}
}
- /// <summary>
- /// Gets all legal key sizes
- /// </summary>
public virtual KeySizes[] LegalKeySizes {
get { return this.LegalKeySizesValue; }
}
- /// <summary>
- /// Gets the signature algorithm
- /// </summary>
- public abstract string SignatureAlgorithm {get;}
+ public abstract string SignatureAlgorithm {
+ get;
+ }
+#if NET_4_0
+ public void Dispose ()
+#else
void IDisposable.Dispose ()
+#endif
{
Dispose (true);
GC.SuppressFinalize (this); // Finalization is now unnecessary
Dispose (false);
}
+#if NET_4_0
+ protected virtual void Dispose (bool disposing)
+ {
+ }
+#else
protected abstract void Dispose (bool disposing);
-
- /// <summary>
- /// Reconstructs the AsymmetricAlgorithm Object from an XML-string
- /// </summary>
+#endif
public abstract void FromXmlString (string xmlString);
- /// <summary>
- /// Returns an XML string representation the current AsymmetricAlgorithm object
- /// </summary>
public abstract string ToXmlString (bool includePrivateParameters);
- /// <summary>
- /// Creates the default implementation of the default asymmetric algorithm (RSA).
- /// </summary>
public static AsymmetricAlgorithm Create ()
{
+#if FULL_AOT_RUNTIME
+ return new RSACryptoServiceProvider ();
+#else
return Create ("System.Security.Cryptography.AsymmetricAlgorithm");
+#endif
}
- /// <summary>
- /// Creates a specific implementation of the given asymmetric algorithm.
- /// </summary>
- /// <param name="algo">Specifies which derived class to create</param>
public static AsymmetricAlgorithm Create (string algName)
{
return (AsymmetricAlgorithm) CryptoConfig.CreateFromName (algName);
}
+
+ // parsing helper shared between DSA and RSA
+ internal static byte [] GetNamedParam (string xml, string param)
+ {
+ string start_element = "<" + param + ">";
+ int start = xml.IndexOf (start_element);
+ if (start == -1)
+ return null;
+
+ string end_element = "</" + param + ">";
+ int end = xml.IndexOf (end_element);
+ if ((end == -1) || (end <= start))
+ return null;
+
+ start += start_element.Length;
+
+ string base64 = xml.Substring (start, end - start);
+ return Convert.FromBase64String (base64);
+ }
}
}
-