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

如何從 C# 中的智能卡讀取憑據(jù)

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

問題描述

在我的組織中,用戶必須使用智能卡以交互方式登錄到 Windows 站點(diǎn)(95、Vista 和 7).幾乎每天,我們都需要讀取存儲(chǔ)在 SmartCard 中的憑據(jù)并將它們與 ActiveDirectory 進(jìn)行比較,而無需實(shí)現(xiàn)自定義憑據(jù)管理器.我們比較的字段是: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 讀取憑據(jù)或引導(dǎo)我閱讀 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 上的搜索建議實(shí)施憑證管理器或使用其他語言(如 C、C++).另外,我看到了這篇文章:http://www.codeproject.com/Articles/17013/Smart-Card-Framework-for-NET 由 orouit 編寫,這是一個(gè)使用智能卡的框架 - 但我認(rèn)為這對(duì)于我的簡(jiǎn)單任務(wù)來說太過分了.你怎么看?

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 下開發(fā),一旦你插入智能卡 windows 會(huì)從智能卡中獲取所有證書并將它們放到我的證書存儲(chǔ)中.

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
  }
}

現(xiàn)在基本上可以通過 .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 和相關(guān)的 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.

你可以得到

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

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

相關(guān)文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應(yīng)該總是在 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#中將空值設(shè)置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時(shí)如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調(diào)用)
主站蜘蛛池模板: 一本一道久久a久久精品综合 | 蜜桃一区二区三区 | 日韩精品一区二区三区中文字幕 | 午夜电影网 | 3级毛片| 欧美一级欧美三级在线观看 | av一区在线观看 | 欧美激情视频一区二区三区在线播放 | 国产免费一区二区 | 午夜不卡一区二区 | 久久久久一区二区 | 久久精品福利 | 二区在线观看 | 国产精品午夜电影 | 久久成人精品视频 | 国产激情91久久精品导航 | 国产精品久久久久免费 | 精品欧美一区二区精品久久 | 成人三级视频在线观看 | 欧美激情五月 | 精品久久久久久久久久久下田 | 日本精品视频在线观看 | 99综合在线 | 你懂的av| 久久99网 | 看a级黄色毛片 | 欧美日韩亚洲二区 | re久久| 久久色视频 | 一区二区三区在线免费 | 色免费在线视频 | 龙珠z国语版在线观看 | 黄色片av| 成人精品国产一区二区4080 | 欧美在线视频一区二区 | 成人做爰9片免费看网站 | 国产精品99久久免费观看 | 桃花av在线 | 91精品久久久久久久久中文字幕 | 日本精品一区二区三区在线观看视频 | 北条麻妃一区二区三区在线视频 |