diff --git a/Aspects/Security/Cryptography/Ciphers/EncryptedKey/Program.cs b/Aspects/Security/Cryptography/Ciphers/EncryptedKey/Program.cs index 31d03fa..b973b7c 100644 --- a/Aspects/Security/Cryptography/Ciphers/EncryptedKey/Program.cs +++ b/Aspects/Security/Cryptography/Ciphers/EncryptedKey/Program.cs @@ -33,22 +33,22 @@ static int Main(string[] args) if (ParseArguments(args) && GetCertificate()) switch (_command) { - case CreateCommand: - _exitCode = Create(); - break; - - case ExportCommand: - _exitCode = Export(); - break; - - case ImportCommand: - _exitCode = Import(); - break; - - case null: - case HelpCommand: - _exitCode = Usage(); - break; + case CreateCommand: + _exitCode = Create(); + break; + + case ExportCommand: + _exitCode = Export(); + break; + + case ImportCommand: + _exitCode = Import(); + break; + + case null: + case HelpCommand: + _exitCode = Usage(); + break; } else Usage(1); @@ -237,7 +237,8 @@ static string GetHexValue(string argument) static bool GetCertificate() { - using (var store = new X509Store(StoreName.My, StoreLocation.CurrentUser)) + var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); + try { store.Open(OpenFlags.ReadOnly); @@ -252,6 +253,10 @@ static bool GetCertificate() return _cert != null; } + finally + { + store.Close(); + } } static IKeyStorage GetKeyStorage()