2

在 .NET 中,我使用以下内容从 .PFX 文件加载证书:

var signingCertificate = new X509Certificate2(pfxFileName);

如果 .PFX 文件需要密码,它会抛出CryptographicException. 我怎样才能知道该文件需要密码(以便我可以提示输入密码)?

4

1 回答 1

2

好吧,您总是可以测试该异常。=)

try
{
    //some stuff
}
catch (CryptographicException ex)
{
    //Now you Know!
}
catch (Exception ex)
{
    //and knowing is half the battle
}
于 2012-02-07T14:34:19.147 回答