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


Java APDU.setOutgoingLength方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例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: sendBuffer

import javacard.framework.APDU; //导入方法依赖的package包/类
public void sendBuffer(byte[] buf, short length, APDU apdu) {
    short le = apdu.setOutgoing();
    short r = 0;

    if (le == 0) {
        le = (short) (APDU.getOutBlockSize() - 2);
    }

    if (le > length) {
        le = length;
    }

    if (le < length) {
        r = (short) (length - le);
        if (r > (short) this.buffer.length) {
            ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
        }
        this.bools[isLOADED] = true;
        this.bools[isFILE]   = false;
        this.shorts[SIZE]    = r;
    }

    apdu.setOutgoingLength(le);
    apdu.sendBytesLong(buf, (short) 0, le);

    if (r > 0) {
        if (r >= (short) (APDU.getOutBlockSize() - 2)) {
            r = 0;
        }
        Util.arrayCopy(buf, le, this.buffer, (short) 0, r);
        ISOException.throwIt((short) (ISO7816.SW_BYTES_REMAINING_00 | r));
    } else {
        clear();
    }
}
 
开发者ID:mbrossard,项目名称:cryptonit-applet,代码行数:36,代码来源:IOBuffer.java

示例8: sendFile

import javacard.framework.APDU; //导入方法依赖的package包/类
public void sendFile(short id, APDU apdu, short offset) {
    byte[] d = index.entries[id].content;
    if (d == null) {
        ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
    }

    short le = apdu.setOutgoing();
    short r = 0;
    if (le == 0) {
        le = (short) (APDU.getOutBlockSize() - 2);
    }

    if ((short) (le + offset) > (short) d.length) {
        le = (short) (d.length - offset);
    }

    if ((short) (le + offset) < (short) d.length) {
        r = (short) (d.length - (le + offset));
        this.bools[isLOADED] = true;
        this.bools[isFILE]   = true;
        this.shorts[OFFSET]  = (short) (le + offset);
        this.shorts[PATH]    = id;
    }

    apdu.setOutgoingLength(le);
    apdu.sendBytesLong(d, offset, le);

    if (r > 0) {
        if (r >= (short) (APDU.getOutBlockSize() - 2)) {
            r = 0;
        }
        ISOException.throwIt((short) (ISO7816.SW_BYTES_REMAINING_00 | r));
    } else {
        clear();
    }
}
 
开发者ID:mbrossard,项目名称:cryptonit-applet,代码行数:37,代码来源:IOBuffer.java

示例9: sendData

import javacard.framework.APDU; //导入方法依赖的package包/类
/********** UTILITY FUNCTIONS **********/

	/*
	 * SendData() wraps the setOutgoing(), setLength(), .. stuff * that could be
	 * necessary to be fully JavaCard compliant.
	 */
	private void sendData(APDU apdu, byte[] data, short offset, short size) {
		if (size > EXT_APDU_BUFFER_SIZE)
			ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
		apdu.setOutgoing();
		apdu.setOutgoingLength(size);
		apdu.sendBytesLong(data, offset, size);
	}
 
开发者ID:Toporin,项目名称:SatoChipApplet,代码行数:14,代码来源:CardEdge.java

示例10: sendLargeData

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * \brief Send the data from ram_buf, using either extended APDUs or GET RESPONSE.
 *
 * \param apdu The APDU object, in STATE_OUTGOING state.
 *
 * \param pos The position in ram_buf at where the data begins
 *
 * \param len The length of the data to be sent. If zero, 9000 will be
 *            returned
 */
private void sendLargeData(APDU apdu, short pos, short len) {
    if(len <= 0) {
        ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_BYTES_REMAINING] = 0;
        ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS] = 0;
        ISOException.throwIt(ISO7816.SW_NO_ERROR);
    }

    if((short)(pos + len) > RAM_BUF_SIZE) {
        ISOException.throwIt(ISO7816.SW_UNKNOWN);
    }

    if(DEF_EXT_APDU) {
        apdu.setOutgoingLength(len);
        apdu.sendBytesLong(ram_buf, pos, len);
    } else {
        // We have 256 Bytes send-capacity per APDU.
        // Send directly from ram_buf, then prepare for chaining.
        short sendLen = len > 256 ? 256 : len;
        apdu.setOutgoingLength(sendLen);
        apdu.sendBytesLong(ram_buf, pos, sendLen);
        short bytesLeft = (short)(len - sendLen);
        if(bytesLeft > 0) {
            ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_BYTES_REMAINING] = bytesLeft;
            ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS] = (short)(pos + sendLen);
            short getRespLen = bytesLeft > 256 ? 256 : bytesLeft;
            ISOException.throwIt( (short)(ISO7816.SW_BYTES_REMAINING_00 | getRespLen) );
            // The next part of the data is now in ram_buf, metadata is in ram_chaining_cache.
            // It can be fetched by the host via GET RESPONSE.
        } else {
            ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_BYTES_REMAINING] = 0;
            ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS] = 0;
            ISOException.throwIt(ISO7816.SW_NO_ERROR);
        }
    }
}
 
开发者ID:philipWendland,项目名称:IsoApplet,代码行数:46,代码来源:IsoApplet.java

示例11: sendData

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * \brief Send the data from ram_buf, using either extended APDUs or GET RESPONSE.
 *
 * \param apdu The APDU object, in STATE_OUTGOING state.
 *
 * \param pos The position in ram_buf at where the data begins
 *
 * \param len The length of the data to be sent. If zero, 9000 will be
 *            returned
 */
private void sendData(APDU apdu) {
    short le;
    short remaininglen = 0;
    byte data[] = null;
    short pos = chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS];

    le = apdu.setOutgoing();
    // le has not been set
    if(le == 0) {
        // we get here when called from the Shared VMWare reader
        byte ins = apdu.getBuffer()[ISO7816.OFFSET_INS];
        if ( ins != GidsApplet.INS_GENERATE_ASYMMETRIC_KEYPAIR) {
            le = 256;
        } else {
            le = 0;
        }
    }

    if (chaining_object[CHAINING_OBJECT] == null) {
        data = ram_buf;
        remaininglen = chaining_cache[RAM_CHAINING_CACHE_OFFSET_BYTES_REMAINING];
    } else if (chaining_object[CHAINING_OBJECT] instanceof Record) {
        Record record = (Record) (chaining_object[CHAINING_OBJECT]);
        data = record.GetData();
        remaininglen = (short) (((short) data.length) - pos);
    } else if (chaining_object[CHAINING_OBJECT] instanceof Record[]) {
        data = ram_buf;
        remaininglen = copyRecordsToRamBuf(le);
        pos = 0;
    }

    // We have 256 Bytes send-capacity per APDU.
    short sendLen = remaininglen > le ? le : remaininglen;
    apdu.setOutgoingLength(sendLen);
    apdu.sendBytesLong(data, pos, sendLen);
    // the position when using Record[] is maintened by copyRecordsToRamBuf
    if (chaining_object[CHAINING_OBJECT] == null || !(chaining_object[CHAINING_OBJECT] instanceof Record[])) {
        chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS]+= sendLen;
    }

    if (chaining_object[CHAINING_OBJECT] == null) {
        chaining_cache[RAM_CHAINING_CACHE_OFFSET_BYTES_REMAINING] -= sendLen;
    }
    remaininglen -= sendLen;
    if(remaininglen > 0) {
        short nextRespLen = remaininglen > 256 ? 256 : remaininglen;
        ISOException.throwIt( (short)(ISO7816.SW_BYTES_REMAINING_00 | nextRespLen) );
    } else {
        Clear(true);
        return;
    }
}
 
开发者ID:vletoux,项目名称:GidsApplet,代码行数:63,代码来源:TransmitManager.java

示例12: computeDigitalSignature

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * \brief Compute a digital signature of the data from the apdu
 * 			using the private key referenced by	an earlier
 *			MANAGE SECURITY ENVIRONMENT apdu.
 *
 * \attention The apdu should contain a hash, not raw data for RSA keys.
 * 				PKCS1 padding will be applied if neccessary.
 *
 * \param apdu The PERFORM SECURITY OPERATION apdu with P1=9E and P2=9A.
 *
 * \throw ISOException SW_CONDITIONS_NOT_SATISFIED, SW_WRONG_LENGTH
 * 						and SW_UNKNOWN.
 */
private void computeDigitalSignature(APDU apdu) throws ISOException {
    byte[] buf = apdu.getBuffer();
    short lc, le;
    short sigLen = 0;
    PrivateKey rsaKey = null;
    byte[] ram_buf = transmitManager.GetRamBuffer();
    CRTKeyFile key = (CRTKeyFile) currentKey[0];

    switch((byte) (currentAlgorithmRef[0] & 0xF0)) {
    case (byte) 0x10:
        // padding made off card -> raw encryption to be performed
        lc = transmitManager.doChainingOrExtAPDU(apdu);

        // RSA signature operation.
        rsaKey = key.GetKey().getPrivate();

        rsaRawCipher.init(rsaKey, Cipher.MODE_ENCRYPT);
        sigLen = rsaRawCipher.doFinal(ram_buf, (short) 0, lc, ram_buf, (short)0);
        // A single short APDU can handle 256 bytes - only one send operation neccessary.
        le = apdu.setOutgoing();
        if(le > 0 && le < sigLen) {
            ISOException.throwIt(ISO7816.SW_CORRECT_LENGTH_00);
        }
        apdu.setOutgoingLength(sigLen);
        apdu.sendBytesLong(ram_buf, (short) 0, sigLen);
        break;
    case (byte) 0x50:
        // rsa padding made by the card, only the hash is provided

        // Receive.
        // Bytes received must be Lc.
        lc = apdu.setIncomingAndReceive();

        // RSA signature operation.
        rsaKey = key.GetKey().getPrivate();

        if(lc > (short) 247) {
            ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
        }
        
        rsaPkcs1Cipher.init(rsaKey, Cipher.MODE_ENCRYPT);
        sigLen = rsaPkcs1Cipher.doFinal(buf, ISO7816.OFFSET_CDATA, lc, ram_buf, (short)0);

        /*if(sigLen != 256) {
            ISOException.throwIt(ISO7816.SW_UNKNOWN);
        }*/

        // A single short APDU can handle 256 bytes - only one send operation neccessary.
        le = apdu.setOutgoing();
        if(le > 0 && le < sigLen) {
            ISOException.throwIt(ISO7816.SW_CORRECT_LENGTH_00);
        }
        apdu.setOutgoingLength(sigLen);
        apdu.sendBytesLong(ram_buf, (short) 0, sigLen);
        break;

    default:
        // Wrong/unknown algorithm.
        ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
    }
}
 
开发者ID:vletoux,项目名称:GidsApplet,代码行数:75,代码来源:GidsApplet.java

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