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


Java APDU.sendBytesLong方法代码示例

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


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

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

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

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

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

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

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


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