title: Asking for a x509 certificate's password from Windows-My store
body: <p>I could get the certificates in Windows-My store with this code:</p>
  
  <pre><code>X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
  store.Open(OpenFlags.IncludeArchived);
  
  X509Certificate2Enumerator enumerator = store.Certificates.GetEnumerator();
  // then I loop through the enumerator and store the certificates in a list
  store.Close();
  </code></pre>
  
  <p>In my app, user selects a certificate and I have to ask for its password. If the password is correct, user can enter the app's options. I can do this with pfx or pkcs12 certificates from user's selected file:</p>
  
  <pre><code>X509Certificate2 cert = new X509Certificate2();
  
  try
  {
      cert.Import(File.ReadAllBytes(pathToMyPfxCert), "my password", X509KeyStorageFlags.DefaultKeySet);
  }
  catch (CryptographicException)
  {
      //wrong password! :D
  }
  </code></pre>
  
  <p>But I'm not sure if this is possible when selecting a certificate from Windows-My. When I exported the Windows-My certificates to a pfx file and imported them again with a wrong password I spected an CryptographicException screaming "The network password is invalid", but I got no exceptions as if I were entering the right password.</p>
  
  <p>Please, also tell me if I'm using Windows-My certificates the wrong way or in a way they were not designed for (I'm a newbie in this x509 stuff).</p>
  
  <p><strong>Edit: About @CryptoGuy comment:</strong></p>
  
  <p>I agree: it is a little odd, because it is a little experimental: we want to know if Windows-My Store certificates can be used for login on a desktop app instead of signing a document.
  My testing certificate is configured in such way that user is asked for the password to access the private key when signing a document:</p>
  
  <p><img src="https://i.stack.imgur.com/9rX8b.png" alt="cert configured to ask for pk&#39;s pw"></p>
  
  <p>The application I'm using to sign files and get this dialog is <a href="http://www.xolido.com/lang/productosxolidosign/xolidosignescritorio/" rel="nofollow noreferrer">XolidoSign</a>.</p>
  
  <p>I want to do the same in my app: ask for the certificate's password (or its private key's password) and check it to login into my app.</p>