我尝试通过 NFC 和 Android 从智能卡读取数据。
我有带应用程序的智能卡。应用程序有 AID(应用程序 ID)A0000006581010
我需要 make SELECT 命令并读取结果。
我写方法:
private static final String SAMPLE_LOYALTY_CARD_AID = "F222222222";
private void performTransaction(Intent nfcIntent) {
Tag tagFromIntent = nfcIntent.getParcelableExtra(EXTRA_TAG);
NfcA mNfc = NfcA.get(tagFromIntent);
try {
mNfc.connect();
//I can read ID
byte[] id = mNfc.getTag().getId();
//I tried create SELECT command
byte[] selCommand = BuildSelectApdu(SAMPLE_LOYALTY_CARD_AID);
//I try send command to card
byte[] result = mNfc.transceive(selCommand);
//I get result == {106, -126}
} catch (IOException e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
} finally {
if (mNfc != null) {
try {
mNfc.close();
} catch (IOException e) {
Log.v("tag", "error closing the tag");
}
}
}
}
如何从智能卡上的具体 AID 发出 SELECT 命令?
SELECT 是标准的 APDU 命令,您可以从Global Platform 中找到定义它的规范。从 AID 构建它是非常机械的:
00A40400 + AID lenght in hexadecimal + AID + 00
例如,对于您的 AIDA0000006581010
的 SELECT 命令是:
00A4040007A000000658101000
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句