Reputation: 16769
I have a task of loading and parsing a given certificate file (or a certificate chain in .p12 file). How can I determine if password is required, so that I can ask the user for it? I can catch CryptographicException
and see if Message is "The specified network password is not correct.\r\n" but I'd rather avoid exceptions and not rely on strings in them.
Upvotes: 0
Views: 756
Reputation: 10431
.Net provides no way of checking if a certificate has a password. So the only of checking without causing an exception would be to use a 3rd party library.
You should instead allow the user to provide the certificate and password at the same time. If they provide a passworded certificate and no password then that would warrant an exception and requesting a password.
Upvotes: 1