2007-04-26 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / tools / security / signcode.cs
index e69f3218d72d078237178a45f53c1561adf9660a..f6df11103bc8b14f4e96963e904b49e2ca4058b6 100644 (file)
@@ -5,7 +5,7 @@
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004,2006-2007 Novell, Inc (http://www.novell.com)
 //
 
 using System;
@@ -62,15 +62,21 @@ namespace Mono.Tools {
                                        return null;
                                }
 
-                               PrivateKey pvk = PrivateKey.CreateFromFile (keyfile);
-                               if (pvk.Encrypted) {
+                               try {
+                                       PrivateKey pvk = PrivateKey.CreateFromFile (keyfile);
+                                       rsa = pvk.RSA;
+                               }
+                               catch (CryptographicException) {
                                        Console.WriteLine ("Enter password for {0}: ", keyfile);
                                        string password = Console.ReadLine ();
-                                       pvk = PrivateKey.CreateFromFile (keyfile, password);
-                                       if (pvk.RSA == null)
+                                       try {
+                                               PrivateKey pvk = PrivateKey.CreateFromFile (keyfile, password);
+                                               rsa = pvk.RSA;
+                                       }
+                                       catch (CryptographicException) {
                                                Console.WriteLine ("Invalid password!");
+                                       }
                                }
-                               rsa = pvk.RSA;
                        }
                        else {
                                rsa = new RSACryptoServiceProvider (csp);
@@ -131,10 +137,10 @@ namespace Mono.Tools {
                                                string auth = args [i++].ToLower ();
                                                switch (auth) {
                                                        case "individual":
-                                                               af.Authority = Authority.Commercial;
+                                                               af.Authority = Authority.Individual;
                                                                break;
                                                        case "commercial":
-                                                               af.Authority = Authority.Individual;
+                                                               af.Authority = Authority.Commercial;
                                                                break;
                                                        default:
                                                                Console.WriteLine ("Unknown authority {0}", auth);