Android 验证和加载密钥失败Mifare Classic 4K
我想读取我的传输卡的余额(或至少能够读取任何扇区),它具有以下技术:NfcA、Mifare Classic、Ndef Formattable。我发现了类似的问题,但没有一个能解决我的问题 我尝试使用默认密钥(keyA和keyB)进行身份验证,但无法 有没有办法验证我的卡?到目前为止,我试过这些钥匙,我从这里找到的 以下是我尝试验证的方式:Android 验证和加载密钥失败Mifare Classic 4K,android,nfc,mifare,Android,Nfc,Mifare,我想读取我的传输卡的余额(或至少能够读取任何扇区),它具有以下技术:NfcA、Mifare Classic、Ndef Formattable。我发现了类似的问题,但没有一个能解决我的问题 我尝试使用默认密钥(keyA和keyB)进行身份验证,但无法 有没有办法验证我的卡?到目前为止,我试过这些钥匙,我从这里找到的 以下是我尝试验证的方式: @Override public void onTagDiscovered(Tag tag) { Log.d(TAG,"tag = &quo
@Override
public void onTagDiscovered(Tag tag) {
Log.d(TAG,"tag = "+tag.toString());
Log.d(TAG,"tag describeContents = "+tag.describeContents());
Log.d(TAG,"tag getId = "+ Arrays.toString(tag.getId()));
Log.d(TAG,"tag getId = "+ Arrays.toString(tag.getTechList()));
MifareClassic mifare = MifareClassic.get(tag);
new Thread( new Runnable() { @Override public void run() {
int ttype = mifare.getType();
Log.d(TAG, "MifareClassic tag type: " + ttype);
int tsize = mifare.getSize();
Log.d(TAG, "tag size: " + tsize);
int s_len = mifare.getSectorCount();
Log.d(TAG, "tag sector count: " + s_len);
int b_len = mifare.getBlockCount();
Log.d(TAG, "tag block count: " + b_len);
try {
mifare.connect();
if (mifare.isConnected()) {
for (byte[] key : defaultKeyList) {
for (int i = 0; i < s_len; i++) {
boolean isAuthenticated = false;
if (mifare.authenticateSectorWithKeyA(i, MifareClassic.KEY_MIFARE_APPLICATION_DIRECTORY) ||
mifare.authenticateSectorWithKeyB(i, MifareClassic.KEY_MIFARE_APPLICATION_DIRECTORY)
) {
isAuthenticated = true;
} else if (mifare.authenticateSectorWithKeyA(i, MifareClassic.KEY_DEFAULT) ||
mifare.authenticateSectorWithKeyB(i, MifareClassic.KEY_DEFAULT)
) {
isAuthenticated = true;
} else if (mifare.authenticateSectorWithKeyA(i, MifareClassic.KEY_NFC_FORUM) ||
mifare.authenticateSectorWithKeyB(i, MifareClassic.KEY_NFC_FORUM)) {
isAuthenticated = true;
} else if (mifare.authenticateSectorWithKeyA(i, key) ||
mifare.authenticateSectorWithKeyB(i, key)) {
isAuthenticated = true;
} else {
Log.d("TAG", "Authorization denied ");
}
if (isAuthenticated) {
Log.d("TAG", "isAuthenticated ");
int block_index = mifare.sectorToBlock(i);
byte[] block = mifare.readBlock(block_index);
String s_block = Utils.Companion.toHex(block);
Log.d(TAG, s_block);
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
} } ).start();
}
我所有钥匙的授权都被拒绝。此外,有人还写道,有些部门同时需要A键和B键,但我不知道如何同时使用这两个键
有没有办法验证这个?我也试着加载钥匙,但我也没能做到。我使用了以下命令:
byte[] LOADKEYS = {
(byte) 0xFF, // CLA Class
(byte) 0x82, // INS Instruction
(byte) 0x00, // P1 Parameter 1
(byte) 0x00, // P2 Parameter 2
(byte) 0x06, // Length
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF,(byte) 0xFF,(byte) 0xFF,(byte) 0xFF
};
byte[] result = mifare.transceive(LOADKEYS)
响应总是10B2
它应该是9000
或6300
。我找不到10B2
的含义。如果有人能启发我,我将不胜感激。提前谢谢
D/MainActivity: tag = TAG: Tech [android.nfc.tech.NfcA, android.nfc.tech.MifareClassic, android.nfc.tech.NdefFormatable]
D/MainActivity: tag describeContents = 0
D/MainActivity: tag getId = [-81, 53, -49, 18]
D/MainActivity: tag getId = [android.nfc.tech.NfcA, android.nfc.tech.MifareClassic, android.nfc.tech.NdefFormatable]
D/MainActivity: MifareClassic tag type: 0
D/MainActivity: tag size: 4096
D/MainActivity: tag sector count: 40
D/MainActivity: tag block count: 256
D/TAG: Authorization denied
D/TAG: Authorization denied
D/TAG: Authorization denied
D/TAG: Authorization denied ...
byte[] LOADKEYS = {
(byte) 0xFF, // CLA Class
(byte) 0x82, // INS Instruction
(byte) 0x00, // P1 Parameter 1
(byte) 0x00, // P2 Parameter 2
(byte) 0x06, // Length
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF,(byte) 0xFF,(byte) 0xFF,(byte) 0xFF
};
byte[] result = mifare.transceive(LOADKEYS)