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


Java APDU.sendBytes方法代码示例

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


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

示例1: send_array

import javacard.framework.APDU; //导入方法依赖的package包/类
public static void send_array(byte[] array, short offset, short len) {
	// get buffer
	APDU apdu = APDU.getCurrentAPDU();
	// This method is failsafe.
	if ((short)(offset + len) > (short)array.length)
		len = (short) (array.length - offset);
	// Copy data
	Util.arrayCopyNonAtomic(array, offset, apdu.getBuffer(), (short)0, len);
	// Check if setOutgoing() has already been called
	if (apdu.getCurrentState() == APDU.STATE_OUTGOING) {
		apdu.setOutgoingLength(len);
		apdu.sendBytes((short)0, len);
	} else {
		apdu.setOutgoingAndSend((short)0, len);
	}
	// Exit normal code flow
	ISOException.throwIt(ISO7816.SW_NO_ERROR);
}
 
开发者ID:martinpaljak,项目名称:esteid-applets,代码行数:19,代码来源:Pro.java

示例2: processGetChallenge

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * \brief Process the GET CHALLENGE instruction (INS=0x84).
 *
 * The host may request a random number of length "Le". This random number
 * is currently _not_ used for any cryptographic function (e.g. secure
 * messaging) by the applet.
 *
 * \param apdu The GET CHALLENGE apdu with P1P2=0000.
 *
 * \throw ISOException SW_INCORRECT_P1P2, SW_WRONG_LENGTH, SW_FUNC_NOT_SUPPORTED.
 */
private void processGetChallenge(APDU apdu) {
    byte[] buf = apdu.getBuffer();
    byte p1 = buf[ISO7816.OFFSET_P1];
    byte p2 = buf[ISO7816.OFFSET_P2];

    if(randomData == null) {
        ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
    }

    if(p1 != 0x00 || p1 != 0x00) {
        ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
    }
    short le = apdu.setOutgoing();
    if(le <= 0 || le > 256) {
        ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
    }
    randomData.generateData(buf, (short)0, le);
    apdu.setOutgoingLength(le);
    apdu.sendBytes((short)0, le);
}
 
开发者ID:philipWendland,项目名称:IsoApplet,代码行数:32,代码来源:IsoApplet.java

示例3: get_data

import javacard.framework.APDU; //导入方法依赖的package包/类
public void get_data(APDU apdu, byte[] buf)
{
	//verify that the class for this instruction is correct
	if((short)(buf[ISO7816.OFFSET_CLA] & 0xFF) != 0x80)
		ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
	//check state - this command only works in the PERSO state
	if(PROFILE.STATE != PERSO)
		ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
	//check that P1 & P2 are correct
	if(buf[ISO7816.OFFSET_P1] != (byte) 0x00 || (byte)buf[ISO7816.OFFSET_P2] != (byte) 0xCF)
		ISOException.throwIt((short)0x6A88); //referenced data not found
	//build response message
	apdu.setOutgoing();
	apdu.setOutgoingLength((short)13);

	buf[0]=(byte)0xCF; //Key Data Tag
	buf[1]=(byte)11;   //length
		buf[2]=PROFILE.VER_KMC;
		Util.arrayCopyNonAtomic(PROFILE.KMC_ID,(short)0,buf,(short)3,(short)6);
		Util.arrayCopyNonAtomic(PROFILE.CSN,(short)0,buf,(short)9,(short)4);
		
	apdu.sendBytes((short)0,(short)13);		
}
 
开发者ID:jiankeliu5,项目名称:CardApplet-PayPass,代码行数:24,代码来源:PayPass.java

示例4: getMobileKey

import javacard.framework.APDU; //导入方法依赖的package包/类
private void getMobileKey(APDU apdu) throws ISOException {
    byte[] apduBuffer = apdu.getBuffer();

    // Check if P1=0x00 and P2=0x00.
    if (Util.getShort(apduBuffer, ISO7816.OFFSET_P1) != (short) 0x0000) {
        ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
    }

    short dataLength = apdu.setOutgoing();
    // Check if Le=0x00.
    if (dataLength != (short) 256) {
        ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
    }

    // Check if Mobile Key is initialized.
    if (!this.dataEncryption.isMobileKeyInit()) {
        ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
    }

    dataLength = this.dataEncryption.getMobileKey(apduBuffer, (short) 0);
    apdu.setOutgoingLength(dataLength);
    apdu.sendBytes((short) 0, dataLength);
}
 
开发者ID:SimplyTapp,项目名称:CardExamples,代码行数:24,代码来源:STPayP.java

示例5: get_data

import javacard.framework.APDU; //导入方法依赖的package包/类
public void get_data(APDU apdu, byte[] buf) {
    // verify that the class for this instruction is correct
    if ((short) (buf[ISO7816.OFFSET_CLA] & 0xFF) != 0x80)
        ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
    // check state - this command only works in the PERSO state
    if (PROFILE.STATE != PERSO)
        ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    // check that P1 & P2 are correct
    if (buf[ISO7816.OFFSET_P1] != (byte) 0x00 || (byte) buf[ISO7816.OFFSET_P2] != (byte) 0xCF)
        ISOException.throwIt((short) 0x6A88); //referenced data not found
    // build response message
    apdu.setOutgoing();
    apdu.setOutgoingLength((short) 13);

    buf[0] = (byte) 0xCF; //Key Data Tag
    buf[1] = (byte) 11;   //length
    buf[2] = PROFILE.VER_KMC;
    Util.arrayCopyNonAtomic(PROFILE.KMC_ID, (short) 0, buf, (short) 3, (short) 6);
    Util.arrayCopyNonAtomic(PROFILE.CSN, (short) 0, buf, (short) 9, (short) 4);

    apdu.sendBytes((short) 0, (short) 13);
}
 
开发者ID:SimplyTapp,项目名称:CardExamples,代码行数:23,代码来源:PayPass.java

示例6: returnPINStatus

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * \brief return information regarding the PIN
 */
public void returnPINStatus(APDU apdu, short id) {
    byte[] buf = apdu.getBuffer();
    GidsPIN pin = null;
    switch(id) {
    default:
        ISOException.throwIt(ErrorCode.SW_REFERENCE_DATA_NOT_FOUND);
        break;
    case (short) 0x7F71:
    case (short) 0x7F72:
        pin = pin_pin;
        break;
    }

    Util.setShort(buf, (short) 0, id);
    buf[2] = (byte) 0x06;
    buf[3] = (byte) 0x97;
    buf[4] = (byte) 0x01;
    buf[5] = pin.getTriesRemaining();
    buf[6] = (byte) 0x93;
    buf[7] = (byte) 0x01;
    buf[8] = pin.getTryLimit();
    apdu.setOutgoing();
    apdu.setOutgoingLength((short)9);
    apdu.sendBytes((short) 0, (short) 9);

}
 
开发者ID:vletoux,项目名称:GidsApplet,代码行数:30,代码来源:GidsPINManager.java

示例7: getProcessingOptions

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * Handle Get Processing Options command.
 * 
 * @param apdu
 *            the incoming <code>APDU</code> object
 * @throws ISOException
 */
private void getProcessingOptions(APDU apdu) throws ISOException {
    byte[] apduBuffer = apdu.getBuffer();

    // DEBUG
    Log.v(LOG_TAG, "C-APDU Header: " + DataUtil.byteArrayToHexString(apduBuffer, 0, 5));

    ByteBuffer apduByteBuffer = ByteBuffer.wrap(apduBuffer);

    // Check if P1=0x00 and P2=0x00.
    if (apduByteBuffer.getShort(ISO7816.OFFSET_P1) != (short) 0x0000) {
        ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
    }

    // Check if Lc=[number of data bytes read].
    // Check if Lc=3.
    // Check if Le=0x00.
    short len = apdu.setIncomingAndReceive();

    // DEBUG
    Log.v(LOG_TAG, "C-APDU: " + DataUtil.byteArrayToHexString(apduBuffer, 0, len + 6));

    if ((len != (short) (apduBuffer[ISO7816.OFFSET_LC] & (short) 0x00FF)) || 
        (len != (short) 3) || 
        (apdu.setOutgoing() != (short) 256)) {
        ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
    }

    // Check PDOL data.
    apduByteBuffer.position(ISO7816.OFFSET_CDATA);
    if (apduByteBuffer.getShort() != (short) 0x8301) {
        ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
    }

    byte terminalType = apduByteBuffer.get();
    // Check if terminal type is offline only.
    if ((terminalType == (byte) 0x13) || 
        (terminalType == (byte) 0x16) || 
        (terminalType == (byte) 0x23) || 
        (terminalType == (byte) 0x26) || 
        (terminalType == (byte) 0x36)) {
        ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
    }

    this.pdolData = new byte[1];
    this.pdolData[0] = terminalType;

    apduByteBuffer.rewind();
    // Build response.
    apduByteBuffer.put(PayPConstants.TAG_RESPONSE_MESSAGE_TEMPLATE);
    // Skip response message template length.
    apduByteBuffer.put((byte) 0);
    // Skip response message template length.
    // Append data elements in response:
    // '82' [2] Application Interchange Profile
    // '94' [var.] Application File Locator
    apduByteBuffer.put(PayPConstants.TAG_AIP);
    apduByteBuffer.put((byte) this.cardProfile.getAip().length);
    apduByteBuffer.put(this.cardProfile.getAip());
    apduByteBuffer.put(PayPConstants.TAG_AFL);
    apduByteBuffer.put((byte) this.cardProfile.getAfl().length);
    apduByteBuffer.put(this.cardProfile.getAfl());
    int rdataLength = apduByteBuffer.position();
    // Set response template message length.
    apduByteBuffer.put(1, (byte) (rdataLength - 2));

    this.apduState = APDU_SENDING;

    // DEBUG
    Log.v(LOG_TAG, "R-APDU: " + DataUtil.byteArrayToHexString(apduBuffer, 0, rdataLength) + "9000");

    apdu.setOutgoingLength((short) rdataLength);
    apdu.sendBytes((short) 0, (short) rdataLength);
}
 
开发者ID:SimplyTapp,项目名称:CardExamples,代码行数:81,代码来源:CardAgent.java


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