- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
一个多星期以来,我一直在尝试使用 Mifare Ultralight C 对 Android 手机进行身份验证。我已经确认我可以写入标签(通过写入不安全的内存页面,然后阅读我写的内容)。我还可以写入关键页 (44-47) 并为所有 16 个关键字节写入 0x00。
当我尝试进行身份验证时,以下是一次交换期间涉及的数据示例 - 它来 self 的应用程序编写的日志。谁能告诉我我做错了什么?我AM保密并可以访问完整数据表。请注意,下面的十六进制字符串显然是正在发送和接收的数据的人类可读版本,在代码中由字节数组组成。
发送验证命令
Received rndB: 8A5735694D9D7542
Key: 00000000000000000000000000000000
IV: 0000000000000000
Decrypted rndB: EF340C62E1B866D4
rndB': 340C62E1B866D4EF
rndA: 6E262630E299F94F
rndA+rndB': 6E262630E299F94F340C62E1B866D4EF
Key: 00000000000000000000000000000000
IV: 8A5735694D9D7542
ek(RndA+rndB'): E36C6C46FAAC60BA45DDF5F5A0802C79
发送 0xAF + E36C6C46FAAC60BA45DDF5F5A0802C79
后我立即失去与标签的连接。我浏览了数据表并阅读了我可以在这里找到的每一篇文章。我还查看了 libfreefare 代码,老实说,我无法弄清楚我做错了什么。
NXP 技术支持完全没有响应。
有什么想法吗?我很茫然。
最佳答案
下面是一个示例 java 代码,用于执行 MF0ICU2 / MIFARE Ultralight C - Contactless ticket IC document 中所述的 Ultralight-C 身份验证。 (第 7.5.5 章——3DES 身份验证,第 15 页):
public void authenticate(byte[] key) throws CardException {
System.out.println("AUTHENTICATE");
byte[] encRndB = transmitRaw(new byte[] { 0x1A, 0x00 });
if((encRndB.length!=9)||(encRndB[0]!=AF)) {
throw new RuntimeException("Invalid response!");
}
encRndB=Arrays.copyOfRange(encRndB, 1, 9);
System.out.println(" - EncRndB: " + toHex(encRndB));
byte[] rndB = desDecrypt(key, encRndB);
System.out.println(" - RndB: " + toHex(rndB));
byte[] rndBrot = rotateLeft(rndB);
System.out.println(" - RndBrot: " + toHex(rndBrot));
byte[] rndA = new byte[8];
generateRandom(rndA);
System.out.println(" - RndA: " + toHex(rndA));
byte[] encRndArotPrime = transmitRaw(ArrayUtils.addAll(new byte[] {AF}, desEncrypt(key, ArrayUtils.addAll(rndA, rndBrot))));
if((encRndArotPrime.length!=9)||(encRndArotPrime[0]!=0x00)) {
throw new RuntimeException("Invalid response!");
}
encRndArotPrime=Arrays.copyOfRange(encRndArotPrime, 1, 9);
System.out.println(" - EncRndArot': " + toHex(encRndArotPrime));
byte[] rndArotPrime = desDecrypt(key, encRndArotPrime);
System.out.println(" - RndArot': " + toHex(rndArotPrime));
if(!Arrays.equals(rotateLeft(rndA), rndArotPrime)) {
throw new RuntimeException("Card authentication failed");
}
}
protected static SecureRandom rnd = new SecureRandom();
protected static void generateRandom(byte[] rndA) {
rnd.nextBytes(rndA);
}
protected byte[] desEncrypt(byte[] key, byte[] data) {
return performDes(Cipher.ENCRYPT_MODE, key, data);
}
protected byte[] desDecrypt(byte[] key, byte[] data) {
return performDes(Cipher.DECRYPT_MODE, key, data);
}
private byte[] iv = new byte[8];
protected byte[] performDes(int opMode, byte[] key, byte[] data) {
try {
Cipher des = Cipher.getInstance("DESede/CBC/NoPadding");
SecretKeyFactory desKeyFactory = SecretKeyFactory.getInstance("DESede");
Key desKey = desKeyFactory.generateSecret(new DESedeKeySpec(ArrayUtils.addAll(key, Arrays.copyOf(key, 8))));
des.init(opMode, desKey, new IvParameterSpec(iv));
byte[] ret = des.doFinal(data);
if(opMode==Cipher.ENCRYPT_MODE) {
iv=Arrays.copyOfRange(ret, ret.length-8, ret.length);
} else {
iv=Arrays.copyOfRange(data, data.length-8, data.length);
}
return ret;
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidKeySpecException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException e) {
throw new RuntimeException(e);
}
}
protected static byte[] rotateLeft(byte[] in) {
return ArrayUtils.add(Arrays.copyOfRange(in, 1, 8), in[0]);
}
注意:此代码使用 Apache Commons Lang .
关于Android:使用 NXP MiFare Ultralight C 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19438554/
在多个 Android 设备上,Mifare DESFire 通信被路由到 HCE 而不是脱离主机 (UICC)。 通过基于 OMAPI 与脱离主机安全元素的通信,我已经学会了如何将 AID 添加到
我需要使用 WinSCard 读取 MiFare 卡的序列号。我能够从 MiFare 卡读取 7B UID。 The confusion is that i dont know if the UID
如何从使用 MIFARE 应用程序目录结构格式化的 MIFARE Classic 卡进行身份验证和读取数据?我正在使用 Android。 最佳答案 请参阅 NXP 关于 MIFARE Applicat
除了 NXP 网站上显示的关于 mifare plus 和 mifare desfire 的内容外,还要考虑以下因素: 安全 阅读速度 如果贴上铁氧体层可以贴在手机上,哪个更好? 如果我们将来要进入支
是否有可靠的方法来确定 RFID 卡是 Mifare Ultralight 还是 Mifare Ultralight C? 到目前为止,我发现的唯一方法是利用这两张卡的大小差异,发出超出较小卡边界的读
我正在 android 中使用 nfc,我想知道发现的标签是 Mifare Classic 还是 Mifare Ultralight 还是其他任何标签。请告诉我该怎么做? 最佳答案 尝试 String
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
我正在尝试将 PN532 配置为 Mifare 仿真模式。我使用“ACR122U”读卡器进行 Mifare 仿真,使用“OMNIKEY CardMan 5x21-CL”作为读卡器。我成功地将 ACR1
假设我想对 Mifare Classic 进行身份验证。 我如何知道要发送到卡的确切类型的 APDU? 例子。 这段代码: bcla = 0xFF; bins = 0x86; bp1 = 0x0;
[ 请在您的答案中仅考虑 1k 经典卡。 ] 我希望获得一些 RFID 领域的行业知识。具体来说,使用 MIFARE MAD(Mifare 应用程序目录)。我通过查看位于此处的 NXP 发布的 MIF
我知道这篇文章:- Locking mechanism of Mifare Classic 1K 但是,确实不清楚 - 如何在此字符串中计算像 FF 07 80 FF 这样的值: D3 F7 D3 F
[ 请在您的答案中仅考虑 1k 经典卡。 ] 我希望获得一些 RFID 领域的行业知识。具体来说,使用 MIFARE MAD(Mifare 应用程序目录)。我通过查看位于此处的 NXP 发布的 MIF
基于 this article ,我正在尝试模拟 mifare 卡在 android 上管理 APDU。根据 APDU 接收,我的应用程序应该回答正确的 APDU,从而模拟 mifare 行为。 使用
好的,我已经开发了一个与 Mifare Classic 智能卡(非接触式)通信的应用程序。 该应用程序将用于成员(member)身份识别。 目前的方法是将一个 16 字节的值写入卡的 block 4。
有没有办法将 DESFire 卡重置为原始状态?是否有格式化和删除所有内容的命令? 我读到 DeleteApplication apdu 命令删除了应用程序及其文件,但空间仍然不可用。 谢谢。 最佳答
这个问题已经有答案了: Reading Mifare Classic returns strange characters (2 个回答) 已关闭 4 年前。 当我从一个 block 读取 Mifar
我编写了一个简单的应用程序 (C#),以便通过我的智能卡读卡器在我的 Mifare 卡上执行一些 I/O 操作(显然,我使用了一些 Win API 包装)。 我得到的关于 mifare 的唯一信息是“
我使用以下命令来执行我的 Mifare Classic 1K 卡的转储: mfoc -O my_dump.mdf 然后我使用以下命令将转储写入空白卡: nfc-mfclassic w A my_dum
我有一个 MIFARE 1K 标签。某些块可以使用身份验证 key A 写入/读取,而其他块可以使用身份验证 key B 写入。 为什么?例如,如何使用键 A 更改要写入/读取的所有块? 比如我可以用
上周我一直在尝试使用具有默认 key (00000000h) 的 MIFARE DESFire EV1 卡进行身份验证,但无济于事。我关注了this blog对信的指示。我实现了Send mode C
我是一名优秀的程序员,十分优秀!