Tag: mifare

DESFire认证解密

我目前正在使用DESFire EV1非接触式卡。 我正在尝试使用主密钥“00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00”解密DES / CBC加密的random_b。 我正在使用此代码: byte[] encipheredCodeRandomB = { (byte)0xEA ,(byte)0x18 ,(byte)0xDE ,(byte)0xFF ,(byte)0x52 ,(byte)0x0E,(byte)0xCD, (byte) 90}; byte[] masterKeyBytes = “0000000000000000”.getBytes(); byte[] ivBytes = “00000000”.getBytes(); DESKeySpec desKeySpec = new DESKeySpec(masterKeyBytes); SecretKeyFactory desKeyFact = SecretKeyFactory.getInstance(“DES”); SecretKey s = desKeyFact.generateSecret(desKeySpec); aliceCipher […]

javax.smartcardio:如何向Desfire卡发送本机命令?

我正在创建一个通过PC / SC非接触式读卡器和javax.smartcardio API与Mifare DESFire卡通信的Java应用程序。 我设法定期发送ISO 7816 APDU(CLA,INS,P1-P2,Lc,Command数据,Le)。 我在Ridrix的博客上看到 ,DESFire卡(至少我使用的EV1版本)支持APDU和Native命令 ,其中大多数命令只有1个字节长。 例如,“ 获取版本 ”命令: Command: 60 Response: af 04 01 01 00 02 18 05 我使用SpringCard的PC / SC Diag程序( 可在此处 )测试了该命令,我得到了正确的响应。 但我无法使用javax.smartcardio发送此命令:此API似乎是为真正的 APDU创建的,因此不允许1字节长的命令。 这是我做的: public static void main(String[] args){ TerminalFactory factory = TerminalFactory.getDefault(); CardTerminals terminalList = factory.terminals(); try { CardTerminal ct = terminalList.list().get(0); ct.waitForCardPresent(0); Card […]

如何解密从Mifare Desfire EV1发送的第一条消息

有没有人知道如何解密从卡发送的第一条消息? 我的意思是在身份validation成功后然后你发送一个命令(例如0x51(GetRealTagUID)。它返回00 + random32bits(总是不同)。我尝试解密它: private byte[] decrypt(byte[] raw, byte[] encrypted, byte[] iv) throws Exception { IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); SecretKeySpec skeySpec = new SecretKeySpec(raw, “AES”); Cipher cipher = Cipher.getInstance(“AES/CBC/NoPadding”); cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivParameterSpec); byte[] decrypted = cipher.doFinal(encrypted); return decrypted; } 用decrypt调用它(sessionKey,response,iv) IV =全零(16字节) 响应= 0x51命令后的32randombits(刚刚删除了两个零) 有人告诉我,第一次发送命令(0x51)后IV发生了变化。 如何生成正确的IV来解密该响应? 我认为全零是错误的,因为解密的消息总是不同的,并且它应该始终与同一张卡相同。 -编辑- 在应用您的(Michael Roland)指令后,解密的响应仍然只是随机位。 这是我的代码(我想我做错了): byte[] x = […]

使用javax.smartcardio从mifare classic中读取块

我想使用Java的javax.smartcardio阅读关于Mifare classic的特定块。 这是我的代码: public byte[] getCardUID() throws CardException { CardTerminals terminals = TerminalFactory.getDefault().terminals(); terminal = terminals.list().get(0); Card card = terminal.connect(“*”); CardChannel channel = card.getBasicChannel(); CommandAPDU command = new CommandAPDU( new byte[] { (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0xD4, (byte) 0x4A, (byte) 0x01, (byte) 0x00 }); ResponseAPDU response = channel.transmit(command); […]

NTAG212 Mifare Ultralight带认证

我是NFC Android的新手,我已经坚持了几天试图通过身份validation获得NTAG212 Mifare Ultralight的第7页,我已经有了PWD和PACK来完成基于NTAG212 Docs的PWD_AUTH 。 我这样做… //assume password as array of bytes //assume pack as array of bytes try{ nfc.connect(); byte[] cmd1 = nfc.transceive(new byte[]{ (byte) 0x30, (byte) 0x00 }); //read the page 0 to make the NFC active nfc.transceive(new byte[]{ (byte) 0x1B, //command for PWD_AUTH pass[0], pass[1], pass[2], pass[3] }); byte[] cmd4 = […]

Mifare Classic 1K的锁定机制

Mifare Classic 1K的程序是 轮询标签 validation这些标签 如果validation成功,则读/写。 我已经完成了这些程序,并且还从特定部门读取和写入数据。 标签的轮询命令是 new byte[] { (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0xD4, (byte) 0x4A, (byte) 0x01, (byte) 0x00 } validation命令是 new byte[] { (byte) 0xFF, (byte) 0x86, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x01,(byte) 0x00, (byte) 0x04, (byte) 0x60,(byte) 0x00 }; 这里“(字节)0x01”是扇区1 并且在扇区1上写入,块5是 […]

使用SCL010获取Mifare Ultralight的UID

我想获得Mifare Ultralight NFC标签的UID。 在Java中我有这个代码: TerminalFactory factory = TerminalFactory.getDefault(); List terminals = factory.terminals().list(); System.out.println(“Terminals: ” + terminals); CardTerminal terminal = terminals.get(0); Card card = terminal.connect(“*”); System.out.println(“card: ” + card); CardChannel channel = card.getBasicChannel(); ResponseAPDU answer = channel.transmit(new CommandAPDU(0xFF, 0xCA, 0x00, 0x00, 0x00)); byte[] uid = answer.getBytes(); 问题是我收到两个字节而不是UID。 有什么问题? APDU是否正确?