java-使用ACR122 NFC读取器读取Apple Pay令牌
作者:互联网
我有一个ACR122 NFC读取器,试图查看我是否可以读取Apple Pay生成的令牌.以下是我尝试使用的Java代码,但每次仅返回4个字母数字字符. Apple Pay iphone可感应nfc读取器-我需要发送特定的apdu命令来检索令牌吗?
import java.io.*;
import java.util.*;
import javax.smartcardio.*;
public class CardTest {
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
int v;
for ( int j = 0; j < bytes.length; j++ ) {
v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}
public static void main(String[] args) throws Exception {
TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null);
System.out.println(factory);
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
if (terminals.isEmpty()) {
throw new Exception("No card terminals available");
}
CardTerminal terminal = terminals.get(0);
// Keep looping looking for cards until the application is closed
while( true )
{
terminal.waitForCardPresent( 0 );
try {
Card card = terminal.connect("*");
CardChannel channel = card.getBasicChannel();
CommandAPDU command = new CommandAPDU(new byte[]{(byte)0xFF,(byte)0xCA,(byte)0x00,(byte)0x00,(byte)0x04});
ResponseAPDU response = channel.transmit(command);
byte[] byteArray = response.getBytes();
System.out.println( bytesToHex( byteArray ) );
Thread.sleep(1000);
} catch (CardException e) {
e.printStackTrace();
}
}
}
}
解决方法:
您发出的命令
FF CA 00 00 04
会为您获取iPhone智能卡(安全元素)的防冲突标识符(如果超过4个字节,则为防冲突标识符的前4个字节).
Apple Pay(通过非接触式界面)对非接触式支付卡实施EMV标准.因此,为了与该非接触式EMV支付卡进行通信,您需要实现该协议.
顺便说一句.不要将支付令牌视为字节字符串.它远不止于此. EMV付款令牌可以是
>由临时“信用卡号”(等)和用于生成交易授权的密钥组成的临时支付“卡”(限于单次/限时/有限次数的交易使用).通常用于HCE应用程序,例如Google Wallet)
>永久付款卡(单独但固定的信用卡号,有效期,秘密密钥等),用于授权以后从链接的信用卡中扣除的付款(->似乎与Apple Pay一起使用-并且还用于基于安全元素的Google电子钱包).
标签:applepay,nfc,acr122,iphone,java 来源: https://codeday.me/bug/20191121/2049465.html