2004-02-09 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Mon, 9 Feb 2004 14:23:56 +0000 (14:23 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Mon, 9 Feb 2004 14:23:56 +0000 (14:23 -0000)
* DSACryptoServiceProvider.cs: Fixed support for key pair persistence.
It now requires (like MS) to call Clear to delete an existing
container. PersistKeyInCsp default value also changes if a
CspParameters is supplied (or not) to the constructor.
* RSACryptoServiceProvider.cs: Same fixes as DSA.

svn path=/trunk/mcs/; revision=22899

mcs/class/corlib/System.Security.Cryptography/ChangeLog
mcs/class/corlib/System.Security.Cryptography/DSACryptoServiceProvider.cs
mcs/class/corlib/System.Security.Cryptography/RSACryptoServiceProvider.cs

index c33db6b0e65fff2ecfd721d9337a49ed1a241c72..eb5cb040d7826752d1959f628affcf9f5ee57045 100644 (file)
@@ -1,3 +1,11 @@
+2004-02-09  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * DSACryptoServiceProvider.cs: Fixed support for key pair persistence.
+       It now requires (like MS) to call Clear to delete an existing 
+       container. PersistKeyInCsp default value also changes if a 
+       CspParameters is supplied (or not) to the constructor.
+       * RSACryptoServiceProvider.cs: Same fixes as DSA.
+
 2004-02-08  Sebastien Pouliot  <sebastien@ximian.com>
 
        * HashAlgorithm.cs: Changed the ComputeHash(Stream) method to (a) not
index 996cba3db31b1655f6f3d422598f4d147237aa9a..e4ee40387724c770a103a9f3522879fb951e327a 100644 (file)
@@ -24,10 +24,10 @@ namespace System.Security.Cryptography {
 #else
        public sealed class DSACryptoServiceProvider : DSA {
 #endif
-               private const int PROV_DSS = 2;         // from WinCrypt.h
+               private const int PROV_DSS = 3;         // from WinCrypt.h
 
                private KeyPairPersistence store;
-               private bool persistKey = true;
+               private bool persistKey;
                private bool persisted;
 
                private bool privateKeyExportable = true;
@@ -53,6 +53,15 @@ namespace System.Security.Cryptography {
 
                public DSACryptoServiceProvider (int dwKeySize, CspParameters parameters)
                {
+                       LegalKeySizesValue = new KeySizes [1];
+                       LegalKeySizesValue [0] = new KeySizes (512, 1024, 64);
+
+                       // will throw an exception is key size isn't supported
+                       KeySize = dwKeySize;
+                       dsa = new DSAManaged (dwKeySize);
+                       dsa.KeyGenerated += new DSAManaged.KeyGeneratedEventHandler (OnKeyGenerated);
+
+                       persistKey = (parameters != null);
                        if (parameters == null) {
                                parameters = new CspParameters (PROV_DSS);
 #if ! NET_1_0
@@ -70,14 +79,6 @@ namespace System.Security.Cryptography {
                                        this.FromXmlString (store.KeyValue);
                                }
                        }
-
-                       LegalKeySizesValue = new KeySizes [1];
-                       LegalKeySizesValue [0] = new KeySizes (512, 1024, 64);
-
-                       // will throw an exception is key size isn't supported
-                       KeySize = dwKeySize;
-                       dsa = new DSAManaged (dwKeySize);
-                       dsa.KeyGenerated += new DSAManaged.KeyGeneratedEventHandler (OnKeyGenerated);
                }
 
                ~DSACryptoServiceProvider ()
@@ -101,14 +102,9 @@ namespace System.Security.Cryptography {
                public bool PersistKeyInCsp {
                        get { return persistKey; }
                        set {
-                               if (value) {
-                                       OnKeyGenerated (dsa);
-                               }
-                               else {
-                                       // delete the container
-                                       store.Remove ();
-                               }
                                persistKey = value;
+                               if (persistKey)
+                                       OnKeyGenerated (dsa);
                        }
                }
 
@@ -207,6 +203,10 @@ namespace System.Security.Cryptography {
                protected override void Dispose (bool disposing) 
                {
                        if (!m_disposed) {
+                               // the key is persisted and we do not want it persisted
+                               if ((persisted) && (!persistKey)) {
+                                       store.Remove ();        // delete the container
+                               }
                                if (dsa != null)
                                        dsa.Clear ();
                                // call base class 
@@ -219,6 +219,7 @@ namespace System.Security.Cryptography {
 
                private void OnKeyGenerated (object sender) 
                {
+                       // the key isn't persisted and we want it persisted
                        if ((persistKey) && (!persisted)) {
                                // save the current keypair
                                store.KeyValue = this.ToXmlString (!dsa.PublicOnly);
index aeed6e71e94d6e9819f5c80187494c1a8be17bc1..1d10c4a46066ccbeec48492ef964043c65b83ffd 100644 (file)
@@ -23,7 +23,7 @@ namespace System.Security.Cryptography {
                private const int PROV_RSA_FULL = 1;    // from WinCrypt.h
 
                private KeyPairPersistence store;
-               private bool persistKey = true;
+               private bool persistKey;
                private bool persisted;
        
                private bool privateKeyExportable = true; 
@@ -65,6 +65,15 @@ namespace System.Security.Cryptography {
        
                private void Common (int dwKeySize, CspParameters p) 
                {
+                       // Microsoft RSA CSP can do between 384 and 16384 bits keypair
+                       LegalKeySizesValue = new KeySizes [1];
+                       LegalKeySizesValue [0] = new KeySizes (384, 16384, 8);
+                       base.KeySize = dwKeySize;
+
+                       rsa = new RSAManaged (KeySize);
+                       rsa.KeyGenerated += new RSAManaged.KeyGeneratedEventHandler (OnKeyGenerated);
+
+                       persistKey = (p != null);
                        if (p == null) {
                                p = new CspParameters (PROV_RSA_FULL);
 #if ! NET_1_0
@@ -82,14 +91,6 @@ namespace System.Security.Cryptography {
                                        this.FromXmlString (store.KeyValue);
                                }
                        }
-
-                       // Microsoft RSA CSP can do between 384 and 16384 bits keypair
-                       LegalKeySizesValue = new KeySizes [1];
-                       LegalKeySizesValue [0] = new KeySizes (384, 16384, 8);
-                       base.KeySize = dwKeySize;
-
-                       rsa = new RSAManaged (KeySize);
-                       rsa.KeyGenerated += new RSAManaged.KeyGeneratedEventHandler (OnKeyGenerated);
                }
 
 #if ! NET_1_0
@@ -123,14 +124,9 @@ namespace System.Security.Cryptography {
                public bool PersistKeyInCsp {
                        get { return persistKey; }
                        set {
-                               if (value) {
-                                       OnKeyGenerated (rsa);
-                               }
-                               else {
-                                       // delete the container
-                                       store.Remove ();
-                               }
                                persistKey = value;
+                               if (persistKey)
+                                       OnKeyGenerated (rsa);
                        }
                }
 
@@ -314,6 +310,10 @@ namespace System.Security.Cryptography {
                protected override void Dispose (bool disposing) 
                {
                        if (!m_disposed) {
+                               // the key is persisted and we do not want it persisted
+                               if ((persisted) && (!persistKey)) {
+                                       store.Remove ();        // delete the container
+                               }
                                if (rsa != null)
                                        rsa.Clear ();
                                // call base class 
@@ -326,6 +326,7 @@ namespace System.Security.Cryptography {
 
                private void OnKeyGenerated (object sender) 
                {
+                       // the key isn't persisted and we want it persisted
                        if ((persistKey) && (!persisted)) {
                                // save the current keypair
                                store.KeyValue = this.ToXmlString (!rsa.PublicOnly);