【问题标题】:prevent windows security popup for missing smart cards防止丢失智能卡的 Windows 安全弹出窗口
【发布时间】:2018-10-01 14:18:00
【问题描述】:

我在Rahul's Blog 找到了这篇关于获取与插入的智能卡关联的证书的文章。 Rahul 建议采用这种方法:

var smartCardCerts = new List<X509Certificate2>();
var myStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
foreach(X509Certificate2 cert in myStore)
{
  if( !cert.HasPrivateKey ) continue; // not smartcard for sure
  var rsa = cert.PrivateKey as RSACryptoServiceProvider;
  if( rsa==null ) continue; // not smart card cert again
  if( rsa.CspKeyContainerInfo.HardwareDevice ) // sure - smartcard
  {
     // inspect rsa.CspKeyContainerInfo.KeyContainerName Property
     // or rsa.CspKeyContainerInfo.ProviderName (your smartcard provider, such as 
     // "Schlumberger Cryptographic Service Provider" for Schlumberger Cryptoflex 4K
     // card, etc
     var name = cert.Name;
     rsa.SignData(); // to confirm presence of private key - to finally authenticate
  }
}

但是,如果未插入智能卡,则会弹出一个 Windows 安全对话框,要求用户选择智能卡设备。

有没有办法阻止这个弹出窗口,而是立即抛出异常?

对我来说最重要的是这条信息:

rsa.CspKeyContainerInfo.HardwareDevice 

如果智能卡丢失,是否有人知道任何其他方法可以在不弹出对话框的情况下访问此信息?

编辑:

在这行代码处弹出Windows安全对话框:

var rsa = cert.PrivateKey as RSACryptoServiceProvider;

【问题讨论】:

  • 感谢您的帮助。不幸的是,它没有让我更进一步。甚至在容器可访问之前,Windows 安全对话框就会弹出。它发生在这一行:var rsa = cert.PrivateKey as RSACryptoServiceProvider;
  • 您可以使用 PCSC API - 似乎有一个用于 C# - 并检查里面是否有智能卡。不过,检测它是否是正确的智能卡可能会比较棘手。

标签: c# smartcard smartcard-reader


【解决方案1】:

使用此代码无法阻止弹出窗口。还有其他方法,例如使用 PCSC 或Setting the PIN of a smartcard programmatically

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 2012-06-07
    • 1970-01-01
    相关资源
    最近更新 更多