简体   繁体   English

如何读取金雅拓智能卡的序列号?

[英]How to read serial number of a Gemalto smart card?

I have smart card and reader (Gemalto). 我有智能卡和读卡器(金雅拓)。 I want to read serial number of card using C#. 我想用C#读取卡的序列号。 I read documents / libraries on Gemalto Support Site but there are no information useful for me. 我在金雅拓支持网站上阅读了文档/图书馆,但没有任何信息对我有用。

I hope someone have exp about Gemalto help me some examples ! 我希望有人对金雅拓有所帮助我帮助我一些例子!

Thanks so much ! 非常感谢 !

You have to send APDU to smart card asking for card product life cycle data ie (CPLC data). 您必须将APDU发送到智能卡,询问卡产品生命周期数据即(CPLC数据)。
Some specific types of cards have Card Production Life Cycle (CPLC) data. 某些特定类型的卡具有卡生产生命周期(CPLC)数据。 For example, JCOP cards have this at GET DATA or GETCPLCDATA at 0x9F7F tag or 0x0101 tag. 例如,JCOP卡在GET DATA或GETCPLCDATA处有0x9F7F标签或0x0101标签。 I believe This is a Global Platform specific tag. 我相信这是一个全球平台特定的标签。 Find what specification your card support. 找出您的卡支持的规格。 For Gemalto card, I hope it will work. 对于金雅拓卡,我希望它能奏效。 Data what i got from my gemalto card by querying CPLC data is: 通过查询CPLC数据从我的金雅拓卡获得的数据是:

For 0x9F7F: 对于0x9F7F:

IC Fabricator :2 Bytes
IC Type : 2 Bytes
Operating System ID : 2 Bytes
Operating System release date : 2 Bytes
Operating System release level : 2 Bytes
IC Fabrication Date : 2 Bytes (Y DDD) date in that year
IC Serial Number : 4 Bytes
IC Batch Identifier : 2 Bytes
IC Module Fabricator : 2 Bytes
IC Module Packaging Date :  2 Bytes
ICC Manufacturer : 2 Bytes
IC Embedding Date :2 Bytes
IC Pre-Personalizer : 2 Bytes
IC Pre-Perso. Equipment Date : 2 Bytes
IC Pre-Perso. Equipment ID : 4 Bytes
IC Personalizer : 4 Bytes
IC Personalization Date : 2 Bytes
IC Perso. Equipment ID : 4 Bytes

For 0x0101: 对于0x0101:

Card serial number: 8 bytes  
Reserved bytes: 3 bytes 0
Flow identification: 1 byte  
Reserved bytes: 4 bytes 

Sorry i cant provide exact bytes and it might vary in your case. 对不起,我无法提供准确的字节,它可能会有所不同。 just check for what tag your card support. 只需检查您的卡支持的标签。 and Better refer to Global Platform documentation and ISO 7816 standard ( http://www.ttfn.net/techno/smartcards/iso7816_4.html ). 更好地参考全球平台文档和ISO 7816标准( http://www.ttfn.net/techno/smartcards/iso7816_4.html )。 I hope This is what you are looking for. 我希望这就是你要找的东西。

If you mean serialnumber on the card you can do following: 如果您的意思是卡上的序列号,您可以执行以下操作:

You need to make reference the to the Off card dll in Gemalto SDK. 您需要参考Gemalto SDK中的Off卡dll。 SmartCard.Runtime.dll SmartCard_Stub.dll SmartCard.Runtime.dll SmartCard_Stub.dll

SmartCard.Transport.PCSC.SelectDialog dialog = new SmartCard.Transport.PCSC.SelectDialog();
CardAccessor ca = new CardAccessor(dialog.SelectedReader);
if(ca.Logon())
{
ca.GetSerialNumber();
}

If you mean serial number on a certificate its a total different approach. 如果你的意思是证书上的序列号,那就是一种完全不同的方法。

Here's how to get it via PowerShell : 以下是如何通过PowerShell获取它:

Note: this is specifically for Gemalto IDPrime .NET cards which are being replaced by the IDPrime MD product line. 注意:这是专门用于由IDPrime MD产品线替换的金雅拓IDPrime .NET卡。 See the end of this post for more info. 有关详细信息,请参阅本文末尾。

Using Gemalto IDPrime .NET SDK 使用Gemalto IDPrime .NET SDK

Add-Type -Path "C:\Program Files (x86)\Gemalto\NET Smartcard Framework SDK\v2.2.180\Libraries\On Card\Framework Libraries\v2.1.213.9175\SmartCard.dll"
Add-Type -Path "C:\Program Files (x86)\Gemalto\NET Smartcard Framework SDK\v2.2.180\bin\SmartCard_stub.dll"
Add-Type -Path "C:\Program Files (x86)\Gemalto\NET Smartcard Framework SDK\v2.2.180\bin\SmartCard.Runtime.dll"
$Reader = New-Object SmartCard.Transport.PCSC.SelectDialog
$Reader.ShowDialog() | Out-Null

$SmartCard = New-Object SmartCard.Accessor.CardAccessor($Reader.SelectedReader)

$SmartCardSN = [System.BitConverter]::ToString($SmartCard.GetSerialNumber())

Write-Host "Smartcard Serial Number: $SmartCardSN"

$SmartCard.Dispose()
$Reader.Dispose()

Using Gemalto IDPrime .NET PKCS #11 Drivers 使用Gemalto IDPrime .NET PKCS#11驱动程序

If you want to use the PKCS11 library, it can be done as follows. 如果要使用PKCS11库,可以按如下方式完成。 However, this route comes with a WARNING since it returns a hash of the serial number and NOT the actual serial number. 但是,此路由附带警告,因为它返回序列号的散列而不是实际的序列号。 Per Gemalto Documentation: 每金雅拓文档:

The .NET PKCS#11 library performs an MD5 hash of the CSN provided by the minidriver giving a result of 16-bytes. .NET PKCS#11库执行由微型驱动程序提供的CSN的MD5哈希,给出16字节的结果。 As the C_GetTokenInfo string is only 16 bytes it can display 16 characters of the hash result only in ASCII format. 由于C_GetTokenInfo字符串仅为16个字节,因此它只能以ASCII格式显示16个字符的哈希结果。 These 16 characters are the 8 MSB (leftmost bytes) of the hash result. 这16个字符是散列结果的8个MSB(最左边的字节)。

Example: 例:

  1. The .NET PKCS#11 library requests the 12-byte Card Serial Number (CSN) from the card ID file: 0x57 0x01 0x13 0x51 0x26 0xC7 0xD6 0x10 0x29 0x27 0xFF 0xFF .NET PKCS#11库从卡ID文件请求12字节卡序列号(CSN):0x57 0x01 0x13 0x51 0x26 0xC7 0xD6 0x10 0x29 0x27 0xFF 0xFF
  2. .NET PKCS#11 performs an MD5 hash on the CSN giving a 16-byte result: 0x05 0xCB 0x00 0x3D 0x76 0xD3 0xE9 0x4F 0x74 0x13 0xD8 0x74 0x38 0x8C 0xBF 0xB4 .NET PKCS#11在CSN上执行MD5哈希,得到16字节结果:0x05 0xCB 0x00 0x3D 0x76 0xD3 0xE9 0x4F 0x74 0x13 0xD8 0x74 0x38 0x8C 0xBF 0xB4
  3. The .NET PKCS#11 transforms the hash into an ASCII string. .NET PKCS#11将哈希转换为ASCII字符串。
  4. Finally it fills the serialNumber field of the TokenInfo structure (on 16 bytes) with the first 16 characters of the ASCII string: “05CB003D76D3E94F” corresponding to the 8 MSB of the hash. 最后,它填充TokenInfo结构的serialNumber字段(在16个字节上),其中包含ASCII字符串的前16个字符:“05CB003D76D3E94F”,对应于散列的8个MSB。
# www.pkcs11interop.net
Add-Type -Path "C:\SomeFolder\Pkcs11Interop.4.0.0\lib\net45\Pkcs11Interop.dll"

# Load Gemalto driver
# 1 = AppType.SingleThreaded
$pkcs11 = New-Object Net.Pkcs11Interop.HighLevelAPI.Pkcs11("C:\Program Files (x86)\Gemalto\DotNet PKCS11\gtop11dotnet64.dll",1)

# 0 = SlotsType.WithTokenPresent
$Slots = $pkcs11.GetSlotList(0)

$CardReader = $Slots[0] # Usually first slot

$CardReader.GetTokenInfo().SerialNumber

$CardReader.CloseAllSessions()
$pkcs11.Dispose()

Gemalto Card Types 金雅拓卡类型

The above examples are based off Gemalto IDPrime .NET cards which are being retired. 以上示例基于正在退休的Gemalto IDPrime .NET卡。 The End of Sale (EOS) announcement is here . 销售终止(EOS)公告就在这里

 IDPrime .Net IDPrime .Net\nIDPrime .Net Bio IDPrime .Net Bio\n\nKey Dates: 关键日期: \nMilestone Date 里程碑日期\nLast-Time-Buy (LTB) September 29, 2017 最后一次购买(LTB)2017年9月29日\nEnd-of-Sale (EOS) September 30, 2017 销售终止(EOS)2017年9月30日\nEnd-of-Life (EOL) September 30, 2018 寿命终止(EOL)2018年9月30日 

Replacement 替代

Per the EOS announcement PDF : 根据EOS公告PDF

Products Gemalto's family of IDPrime .NET 510/511 smart cards will be replaced by the IDPrime MD 83x and IDPrime MD 84x series of smart cards. 产品Gemalto的IDPrime .NET 510/511智能卡系列将被IDPrime MD 83xIDPrime MD 84x系列智能卡取代。

Programming the Replacement cards 编程替换卡

I've included the information about distinguishing card types because I have a Gemalto IDPrime MD 830 for testing and the above techniques do not work. 我已经包含了有关区分卡类型的信息,因为我有一个金雅拓IDPrime MD 830用于测试,上述技术不起作用。 In fact, the card doesn't even show as being present in the reader using the above techniques. 实际上,使用上述技术,卡甚至不显示在阅读器中。

See this post . 这篇文章 Things might differ slightly on your card (CLA byte in particular). 卡上的情况可能略有不同(特别是CLA字节)。

Basically you need to select the root of the card file system (MF, aka 3F00), then select the card's EFiccid (2FE2) and read the contents. 基本上你需要选择卡片文件系统的根(MF,又名3F00),然后选择卡片的EFiccid(2FE2)并阅读内容。 Pretty simple in theory. 理论上非常简单。

For each step there is a dedicated APDU command. 对于每个步骤,都有一个专用的APDU命令。 If the Gemalto library allows you to send APDUs, you should be good to go. 如果金雅拓库允许您发送APDU,那么您应该很高兴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM