我想從ID卡讀取特定信息。訪問智能卡文件結構
我想獲得姓名,身份證號碼,DOB等。這是一張智能卡。
我已經編寫了一個Java程序,連接到讀卡器和卡也。
唯一的問題是,當我想從卡中讀取信息時,我不清楚DF(專用文件)或EF(基本文件)位於何處。 MF是固定的3F00,但其他人我不知道。
這是比利時身份證文件位置的例子:
static byte[] IDENTITY_FILE_AID = new byte[] {
(byte) 0x3F,// MASTER FILE, Head directory MF "3f00"
(byte) 0x00,
(byte) 0xDF,// Dedicated File, subdirectory identity DF(ID) "DF01"
(byte) 0x01,
(byte) 0x40,// Elementary File, the identity file itself EF(ID#RN) "4031"
(byte) 0x31 };
但這不是我們的身份證在我們的國家和政府的工作,不提了卡的結構。有沒有什麼方法可以知道結構或讀取整個卡而不提及特定的文件?
文件與選擇:
CommandAPDU selectFileApdu = new CommandAPDU(
0x00, //CLA
0xA4, //INS
0x08, //P1
0x0C, //P2
IDENTITY_FILE_AID);
我認爲唯一的問題是:
IDENTITY_FILE_AID
這是整個程序代碼:
import java.util.*;
import javax.smartcardio.*;
public class Mainn {
static byte[] IDENTITY_FILE_AID = new byte[] {
(byte) 0x3F,// MASTER FILE, Head directory MF "3f00"
(byte) 0x00,
(byte) 0xDF,// Dedicated File, subdirectory identity DF(ID) "DF01"
(byte) 0x01,
(byte) 0x40,// Elementary File, the identity file itself EF(ID#RN) "4031"
(byte) 0x31
};
static byte FIRST_NAME_TAG = (byte) 0x08;
static byte LAST_NAME_TAG = (byte) 0x07;
static byte NATIONAL_NUMBER_TAG = (byte) 0x06;
static byte BIRTH_DATE_TAG = (byte) 0x0C;
///////////////////////////// Let's program it now !
public static void main(String[] args) {
TerminalFactory factory = TerminalFactory.getDefault();
try{
System.out.println("First");
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Second");
// get the first terminal
// This is the device for reading the card
CardTerminal terminal = terminals.get(0);
System.out.println("Third");
// establish a connection with the card
Card card = terminal.connect("*");
System.out.println("Fourth");
CardChannel channel = card.getBasicChannel();
System.out.println("Fifth");
// SELECT FILE COMMAND
// See BEID cardpecs v2.0 page 21
CommandAPDU selectFileApdu = new CommandAPDU(
0x00, //CLA
0xA4, //INS
0x08, //P1
0x0C, //P2
IDENTITY_FILE_AID);
ResponseAPDU r = channel.transmit(selectFileApdu);
int offset = 0;
byte[] file = new byte[4096];
byte[] data;
do {
CommandAPDU readBinaryApdu = new CommandAPDU(
0x00, //CLA
0xB0, //Read binary command
offset >> 8, //OFF_H higher byte of the offset (bit 8 = 0)
offset & 0xFF, //OFF_L lower byte of the offset
0xFF); //empty
ResponseAPDU responseApdu = channel.transmit(readBinaryApdu);
data = responseApdu.getData();
System.arraycopy(data, 0, file, offset, data.length);
offset += data.length;
}
while (0xFF == data.length);
card.disconnect(false);
// locate the first name field within the identity file
System.out.println("Sixth");
int idx = 0;
byte length = 0;
while (idx < file.length) {
byte tag = file[idx];
idx++;
length = file[idx];
idx++;
String firstName = new String(Arrays.copyOfRange(file, idx, idx + length));
System.out.println("first name: " + firstName);
idx += length;
}
}
catch(CardException ioe) {
System.out.println("Something Wrong With The Insertion of the reader or the card");
}
}
}
我遇到的問題是我不知道信息的保存位置。
那我該怎麼辦?
什麼是卡類型? –
IDENTITY SMART CARD是一種Java混合智能卡,由66K EEPROM ST微型觸點和1K EEPROM非接觸式mifare芯片組成。 – user3800653
某些mifare卡有一些安全漏洞,允許您從卡中讀取任意信息 - 有一些工具可以執行,例如https://code.google.com/p/mfcuk/和http:// nfc-tools。 org/index.php?title = Libnfc:nfc-mfclassic - 只需挖掘一下這個,我想你可以做點什麼 –