当前位置: 首页>>代码示例>>Java>>正文


Java CardResponse.getData方法代码示例

本文整理汇总了Java中sasc.terminal.CardResponse.getData方法的典型用法代码示例。如果您正苦于以下问题:Java CardResponse.getData方法的具体用法?Java CardResponse.getData怎么用?Java CardResponse.getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sasc.terminal.CardResponse的用法示例。


在下文中一共展示了CardResponse.getData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getChallenge

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
/**
 * EMV 4.2 Book 3, section 6.5.6
 * The GET CHALLENGE command is used to obtain an unpredictable number from 
 * the ICC for use in a security-related procedure. 
 * The challenge shall be valid only for the next issued command.
 * 
 * Used eg when enciphering the PIN
 * 
 * @return an 8-byte unpredictable number generated by the ICC, 
 *    or a zero length byte array if the card does not support the command or the response data length != 8 
 * @throws TerminalException 
 */
private byte[] getChallenge() throws TerminalException {

    byte[] command;

    Log.commandHeader("Send GET CHALLENGE command");
    command = EMVAPDUCommands.getChallenge();

    //Parse raw bytes only, no BERTLV
    CardResponse getChallengeResponse = EMVUtil.sendCmdNoParse(terminal, command);
    
    
    if (getChallengeResponse.getSW() == SW.SUCCESS.getSW()) {
        //The data field of the response message should contain an 
        //8-byte unpredictable number generated by the ICC
        byte[] challenge = getChallengeResponse.getData();
        return challenge;
    }
    return new byte[0];
}
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:32,代码来源:EMVSession.java

示例2: process

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
@Override
public boolean process(SmartCard card, CardConnection terminal) throws TerminalException {
    Log.debug("Attempting to read storage card");
    
    byte SW1;
    byte SW2;
    byte[] command;
    CardResponse response;
    byte[] data;
    
    //6a 81 = Function not supported
    //90 00 = Success 
    Log.commandHeader("PS/SC GET DATA: UID (Command handled by terminal when card is contactless)");

    command = Util.fromHexString("ff ca 00 00 00"); //PC/SC 2.01 part 3 GetData: UID
    response = EMVUtil.sendCmdNoParse(terminal, command);
    SW1 = (byte) response.getSW1();
    SW2 = (byte) response.getSW2();
    if (response.getSW() == SW.SUCCESS.getSW()) {
        
    }
    
    Log.commandHeader("PC/SC GET DATA: Historical bytes (Command handled by terminal when card is contactless)");

    command = Util.fromHexString("ff ca 01 00 00"); //PC/SC 2.01 part 3 GetData: historical bytes from the ATS of a ISO 14443 A card without CRC
    response = EMVUtil.sendCmdNoParse(terminal, command);
    SW1 = (byte) response.getSW1();
    SW2 = (byte) response.getSW2();
    if (response.getSW() == SW.SUCCESS.getSW()) {
        
    }
    
    //Read Binary

    //    Warning
    //      6281 Part of returned data may be corrupted.
    //        82 End of file reached before reading expected number of bytes.
    //      6981 Command incompatible.
    //        82 Security status not satisfied.
    //        86 Command not allowed.
    //      6A81 Function not supported.
    //        82 File not found / Addressed block or byte does not exist.
    //
    //    Error
    //      6CXX Wrong length (wrong number Le; 'XX' is the exact number). 
    
    int addressMSB = 0;
    int addressLSB = 0;
    while(addressMSB < 256) {
        Log.commandHeader("PC/SC Read Binary (Storage Card)");
        command = Util.fromHexString("FF B0 00 00 00"); //with Le
        command[2] = (byte)addressMSB;
        command[3] = (byte)addressLSB;
        response = EMVUtil.sendCmdNoParse(terminal, command);
        SW1 = response.getSW1();
        SW2 = response.getSW2();
        data = response.getData();
        if(data.length > 0 && response.getSW() == SW.SUCCESS.getSW()){
            addressLSB++;
            if(addressLSB > 255) {
                addressLSB = 0;
                addressMSB++;
            }
            continue;
        }
        break;
    } 
    return false; //Don't handle exclusively. The card may have more applications or other functionality
}
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:70,代码来源:StorageCardHandler.java

示例3: sendCmdInternal

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
private static CardResponse sendCmdInternal(CardConnection terminal, byte[] cmd, boolean doParseTLVData) throws TerminalException {
    byte[] cmdBytes = checkAndAddLeIfMissing(cmd);
    Log.command(Util.prettyPrintHex(cmdBytes));
    long startTime = System.nanoTime();
    CardResponse response = terminal.transmit(cmdBytes);

    //handle procedure bytes here, and not in the lower level TerminalProvider Implementations.
    //That way we can process procedure bytes from any Provider (if they are not handled at that level)

    byte sw1 = (byte) response.getSW1();
    byte sw2 = (byte) response.getSW2();
    byte[] data = response.getData(); //Copy
    Log.debug("Received data+SW1+SW2: " + Util.byteArrayToHexString(data) + " " + Util.byte2Hex(sw1) + " " + Util.byte2Hex((byte) sw2));
    Log.debug("data.length: 0x"+Util.int2Hex(data.length) + " ("+data.length+")");
    if (sw1 == (byte) 0x6c) { //"Wrong length" (resend last command with correct length)
        //Re-issue command with correct length
        cmdBytes[4] = sw2;
        Log.procedureByte("Received procedure byte SW1=0x6c. Re-issuing command with correct length (" + Util.byte2Hex(sw2)+"): "+ Util.byteArrayToHexString(cmdBytes));
        response = terminal.transmit(cmdBytes);
        sw1 = (byte) response.getSW1();
        sw2 = (byte) response.getSW2();
        data = response.getData(); //Copy
        Log.procedureByte("Received data+SW1+SW2: " + Util.byteArrayToHexString(data) + " " + Util.byte2Hex(sw1) + " " + Util.byte2Hex(sw2));
    }

    //Note some non-EMV cards (and terminal software) seem to re-issue the last command with length=SW2 when getting SW1=61
    while (sw1 == (byte) 0x61) { //Procedure byte: send GET RESPONSE to receive more data
        boolean emvMode = true;
        if(emvMode){
            //this command is EMV specific, since EMV locks CLA to 0x00 only (Book 1, 9.3.1.3). ISO7816-4 specifies CLS in GET RESPONSE in "section 5.4.1 Class byte" to be 0x0X
            cmdBytes = new byte[]{(byte) 0x00, (byte) 0xC0, (byte) 0x00, (byte) 0x00, (byte) sw2};
        }else{
            cmdBytes = new byte[]{cmdBytes[0], (byte) 0xC0, (byte) 0x00, (byte) 0x00, (byte) sw2};
        }
        Log.procedureByte("Received procedure byte SW1=0x61. Sending GET RESPONSE command: " + Util.byteArrayToHexString(cmdBytes));
        response = terminal.transmit(cmdBytes);
        byte[] newData = response.getData();
        byte[] tmpData = new byte[data.length + newData.length];
        System.arraycopy(data, 0, tmpData, 0, data.length);
        System.arraycopy(newData, 0, tmpData, data.length, newData.length);
        sw1 = (byte) response.getSW1();
        sw2 = (byte) response.getSW2();
        Log.procedureByte("Received newData+SW1+SW2: " + Util.byteArrayToHexString(newData) + " " + Util.byte2Hex(sw1) + " " + Util.byte2Hex(sw2));
        data = tmpData;
    }


    long endTime = System.nanoTime();
    printResponse(response, doParseTLVData);
    Log.debug("Time: " + Util.getFormattedNanoTime(endTime - startTime));
    return response;
}
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:53,代码来源:EMVUtil.java

示例4: initCard

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
public EMVCard initCard() throws TerminalException {
    card = new EMVCard(new sasc.iso7816.ATR(seConn.getATR()));

    // ATR file
    String command = "00 A4 00 00 02 2F01";
    CardResponse response = seConn.transmit(fromHex(command));
    if (response.getSW() == SW.SUCCESS.getSW()) {
        card = new EMVCard(new sasc.iso7816.ATR(response.getData()));
    } else {
        Log.d(TAG, "ATR file not found. Will use dummy. Response: "
                + response);
        card = new EMVCard(
                new sasc.iso7816.ATR(
                        Hex.fromHex("3B 8A 80 01 00 31 C1 73 C8 40 00 00 90 00 90")));
    }

    // try to select the PPSE (Proximity Payment System Environment)
    // 2PAY.SYS.DDF01
    Log.d(TAG, "SELECT FILE 2PAY.SYS.DDF01 to get the PPSE directory");
    command = EMVAPDUCommands.selectPPSE();
    CardResponse selectPPSEdirResponse = EMVUtil.sendCmd(seConn, command);
    short sw = selectPPSEdirResponse.getSW();
    if (sw == SW.SUCCESS.getSW()) {
        Log.d(TAG, "***************************************************");
        // PPSE is available
        DDF ppse = PPSE.parse(selectPPSEdirResponse.getData(), card);
        Log.d(TAG, "Name: " + new String(ppse.getName()));
        Log.d(TAG, "PPSE DDF: " + ppse.toString());
        card.setType(EMVCard.Type.CONTACTLESS);
        card.setPSE(ppse);

        // loopback command test
        response = EMVUtil.sendCmd(seConn, "80ee00000301020300");
        Log.d(TAG, "loopback response: " + response.toString());
    }

    // Still no applications?
    if (card.getApplications().isEmpty()) {
        Log.d(TAG,
                "No PSE '2PAY.SYS.DDF01' or application(s) found. Might not be an EMV card. Is Wallet locked?");
    }

    cardInitalized = true;
    return card;
}
 
开发者ID:gsbabil,项目名称:ClassicNFC,代码行数:46,代码来源:SEEMVSession.java


注:本文中的sasc.terminal.CardResponse.getData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。