New tests.
[mono.git] / mcs / class / corlib / Mono.Security.Cryptography / PKCS8.cs
index d7cedf758f63a8c6116a45964a33d6efdb15fe7f..84b830f245835b9db8069e4f126f7261a636fa1f 100644 (file)
@@ -6,7 +6,7 @@
 //     Sebastien Pouliot <sebastien@ximian.com>
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004-2005 Novell Inc. (http://www.novell.com)
+// Copyright (C) 2004-2006 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
@@ -272,9 +272,25 @@ namespace Mono.Security.Cryptography {
                                param.InverseQ = Normalize (privateKey [8].Value, keysize2);
                                param.P = Normalize (privateKey [4].Value, keysize2);
                                param.Q = Normalize (privateKey [5].Value, keysize2);
-
+#if MOONLIGHT
                                RSA rsa = RSA.Create ();
                                rsa.ImportParameters (param);
+#else
+                               RSA rsa = null;
+                               try {
+                                       rsa = RSA.Create ();
+                                       rsa.ImportParameters (param);
+                               }
+                               catch (CryptographicException) {
+                                       // this may cause problem when this code is run under
+                                       // the SYSTEM identity on Windows (e.g. ASP.NET). See
+                                       // http://bugzilla.ximian.com/show_bug.cgi?id=77559
+                                       CspParameters csp = new CspParameters ();
+                                       csp.Flags = CspProviderFlags.UseMachineKeyStore;
+                                       rsa = new RSACryptoServiceProvider (csp);
+                                       rsa.ImportParameters (param);
+                               }
+#endif
                                return rsa;
                        }
 
@@ -322,7 +338,7 @@ namespace Mono.Security.Cryptography {
                                        throw new CryptographicException ("invalid private key format");
 
                                // X is ALWAYS 20 bytes (no matter if the key length is 512 or 1024 bits)
-                               dsaParameters.X = Normalize (privateKey, 20);
+                               dsaParameters.X = Normalize (pvk.Value, 20);
                                DSA dsa = DSA.Create ();
                                dsa.ImportParameters (dsaParameters);
                                return dsa;