久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從 C# 中的智能卡讀取憑據

How to read credentials from a SmartCard in c#(如何從 C# 中的智能卡讀取憑據)
本文介紹了如何從 C# 中的智能卡讀取憑據的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在我的組織中,用戶必須使用智能卡以交互方式登錄到 Windows 站點(95、Vista 和 7).幾乎每天,我們都需要讀取存儲在 SmartCard 中的憑據并將它們與 ActiveDirectory 進行比較,而無需實現自定義憑據管理器.我們比較的字段是:userPrincialName 和 sAMAccountName.

In my organization, users must use SmartCard for interactive login to a Windows stations (95,Vista and 7). almost daily, we need to read the credentials stored in the SmartCard and compaire them with the ActiveDirectory, without implementing a custom credentials manager. The fields we compare are: userPrincialName and sAMAccountName.

能否給我看一段代碼,演示如何從 SmartCard 讀取憑據或引導我閱讀 Internet 上的文章/代碼?

Can you please show me a code that demonstrates how to read the credentials from the SmartCard or guide me to an article / code on the internet?

在 Internet 上的搜索建議實施憑證管理器或使用其他語言(如 C、C++).另外,我看到了這篇文章:http://www.codeproject.com/Articles/17013/Smart-Card-Framework-for-NET 由 orouit 編寫,這是一個使用智能卡的框架 - 但我認為這對于我的簡單任務來說太過分了.你怎么看?

A search over internet suggeted implementing credentials manager or using other languages (like C, C++). Also, I came across this article : http://www.codeproject.com/Articles/17013/Smart-Card-Framework-for-NET written by orouit, which is a framework for working with SmartCards - but I think this too much for my simple task. What do you think?

推薦答案

好吧,如果在 windows 下開發,一旦你插入智能卡 windows 會從智能卡中獲取所有證書并將它們放到我的證書存儲中.

Well if developing under windows, once you insert smart card windows will fetch all certificates from the smart card place them to the My certificate store.

var smartCardCerts = new List<X509Certificate2>();
var myStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
myStore.Open(OpenFlags.ReadOnly);
foreach(X509Certificate2 cert in myStore.Certificates)
{
  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
  }
}

現在基本上可以通過 .NET 獲得很多加密 API.但是你也可以直接使用 API Crypto API

basically a lot of crypto API is available via .NET nowdays. But you could also use API directly Crypto API

例如您可以通過

CryptAcquireContext(&hProv,"\.<Reader Name><Container Name>",...)

其中讀卡器名稱是讀卡器名稱,容器名稱是上面代碼片段中的任何 rsa.KeyContainerName.有多種方法可以訪問這樣的信息,而 Crypto API 不是很一致或直接.作為提示,.NET 版本的 CryptAcquireContext 是帶有 CspParameters 的 RSACryptoServiceProvider,如果需要,您可以在其中指定容器名稱.

where reader name is card reader name and container name is whatever rsa.KeyContainerName in code snippet above. There are multiple ways to access information like that and Crypto API is not very consistent or straightforward. as a hint .NET version of CryptAcquireContext is RSACryptoServiceProvider with CspParameters where you can specify container name if needed.

在 ActiveDirectory 中找到用戶可以通過 System.DirectoryServices.DirectoyEntry 和 System.DirectoryServices.DirectorySearcher 來完成,但不要忘記 System.DirectoryServices.ActiveDirectory.Forest 和相關的 API,它使某些事情更容易弄清楚.

Well finding user in ActiveDirectory may be done via System.DirectoryServices.DirectoyEntry and System.DirectoryServices.DirectorySearcher, but do not forget System.DirectoryServices.ActiveDirectory.Forest and related API which makes some things a lot easier to figure out.

你可以得到

這篇關于如何從 C# 中的智能卡讀取憑據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應該總是在 C# 中使用可空類型)
C# HasValue vs !=null(C# HasValue vs !=null)
C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有沒有更高效的語法?)
How to set null value to int in c#?(如何在c#中將空值設置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調用)
主站蜘蛛池模板: 久久成人精品视频 | 夜夜骑综合 | 欧美精品国产一区二区 | 日韩成人av在线播放 | 日韩中文字幕视频 | 日韩一区二区免费视频 | 精品福利在线视频 | 欧美性猛交一区二区三区精品 | 免费精品| 欧美久久精品 | 99热在线免费 | 不卡av电影在线播放 | 亚洲视频第一页 | 国产乱码精品一区二区三区五月婷 | 夜夜爽99久久国产综合精品女不卡 | 国产精品一区二区不卡 | 欧美影院 | 久久久久国产精品www | 亚洲黄色成人网 | 成人午夜免费网站 | 天天综合网7799精品 | 四虎成人免费视频 | 日本成人在线观看网站 | 国产高清视频在线观看 | 久久精品黄色 | 中文字幕日韩欧美 | 久久久久久亚洲精品 | 国产精品中文在线 | a国产视频 | 国产在线观看一区二区 | 亚洲xx在线 | 欧美日韩三级 | 夜夜摸天天操 | 国产精品久久av | 久久日韩粉嫩一区二区三区 | 欧美一区免费在线观看 | 久久精品色视频 | 欧美视频1区| 视频一区二区三区在线观看 | 国产午夜精品一区二区三区四区 | 久久久久香蕉视频 |