本文整理汇总了Java中javacard.framework.APDU.getBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java APDU.getBuffer方法的具体用法?Java APDU.getBuffer怎么用?Java APDU.getBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javacard.framework.APDU
的用法示例。
在下文中一共展示了APDU.getBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: KeyGen_StoreCommitment
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* Upon the generation of the triplet, the members perform a pairwise
* exchange of their commitments by the end of which, they all hold a
* set H = {h1,h2, ..,ht }. The commitment exchange terminates when |Hq | =
* t ∀q ∈ Q
* @param apdu
*/
void KeyGen_StoreCommitment(APDU apdu) {
byte[] apdubuf = apdu.getBuffer();
short len = apdu.getIncomingLength();
short paramsOffset = GetOperationParamsOffset(Consts.INS_KEYGEN_STORE_COMMITMENT, apdu);
// Parse incoming apdu to obtain target quorum context
QuorumContext quorumCtx = GetTargetQuorumContext(apdubuf, paramsOffset);
// Verify authorization
quorumCtx.VerifyCallerAuthorization(apdu, StateModel.FNC_QuorumContext_StoreCommitment);
// Store provided commitment
short playerId = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTORECOMMITMENT_PLAYERID_OFFSET));
short commitmentLen = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTORECOMMITMENT_COMMITMENTLENGTH_OFFSET));
quorumCtx.StoreCommitment(playerId, apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTORECOMMITMENT_COMMITMENT_OFFSET), commitmentLen);
}
示例2: test_EC_MUL
import javacard.framework.APDU; //导入方法依赖的package包/类
void test_EC_MUL(APDU apdu) {
byte[] apdubuf = apdu.getBuffer();
short p1_len = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);
PM.check(PM.TRAP_EC_MUL_1);
Bignat scalar = m_testBN1;
scalar.set_size(p1_len);
scalar.from_byte_array(p1_len, (short) 0, apdubuf, ISO7816.OFFSET_CDATA);
PM.check(PM.TRAP_EC_MUL_2);
m_testPoint1.setW(apdubuf, (short) (ISO7816.OFFSET_CDATA + p1_len), m_testCurve.POINT_SIZE);
PM.check(PM.TRAP_EC_MUL_3);
m_testPoint1.multiplication(scalar);
PM.check(PM.TRAP_EC_MUL_4);
short len = m_testPoint1.getW(apdubuf, (short) 0);
PM.check(PM.TRAP_EC_MUL_5);
apdu.setOutgoingAndSend((short) 0, len);
}
示例3: process
import javacard.framework.APDU; //导入方法依赖的package包/类
public void process(APDU apdu) {
// Good practice: Return 9000 on SELECT
if (selectingApplet()) {
return;
}
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x00:
handleGetPRand(apdu);
break;
case (byte) 0x01:
handleGetCmac(apdu);
break;
default:
// good practice: If you don't know the INStruction, say so:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
示例4: test_BN_EXP
import javacard.framework.APDU; //导入方法依赖的package包/类
void test_BN_EXP(APDU apdu, short dataLen) {
byte[] apdubuf = apdu.getBuffer();
short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);
short p2 = (short) (apdubuf[ISO7816.OFFSET_P2] & 0x00FF);
PM.check(PM.TRAP_BN_EXP_1);
Bignat base = m_testBN1;
base.set_size(p1);
PM.check(PM.TRAP_BN_EXP_2);
Bignat exp = m_testBN2;
exp.set_size((short) (dataLen - p1));
PM.check(PM.TRAP_BN_EXP_3);
Bignat res = m_testBN3;
res.set_size((short) (m_ecc.MAX_BIGNAT_SIZE / 2));
PM.check(PM.TRAP_BN_EXP_4);
base.from_byte_array(p1, (short) 0, apdubuf, ISO7816.OFFSET_CDATA);
exp.from_byte_array((short) (dataLen - p1), (short) 0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1));
PM.check(PM.TRAP_BN_EXP_5);
res.exponentiation(base, exp);
PM.check(PM.TRAP_BN_EXP_6);
short len = res.copy_to_buffer(apdubuf, (short) 0);
apdu.setOutgoingAndSend((short) 0, len);
}
示例5: test_INT_ADD
import javacard.framework.APDU; //导入方法依赖的package包/类
void test_INT_ADD(APDU apdu, short dataLen) {
byte[] apdubuf = apdu.getBuffer();
short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);
PM.check(PM.TRAP_INT_ADD_1);
//Integer num_add_1 = new Integer(dataLen, (short) 0, apdubuf, ISO7816.OFFSET_CDATA);
Integer num_add_1 = m_testINT1;
num_add_1.fromByteArray(apdubuf, ISO7816.OFFSET_CDATA, p1);
PM.check(PM.TRAP_INT_ADD_2);
//Integer num_add_2 = new Integer((short) (dataLen - p1), (short) 0, apdubuf, (short) (ISO7816.OFFSET_CDATA + p1));
Integer num_add_2 = m_testINT2;
num_add_2.fromByteArray(apdubuf, (short) (ISO7816.OFFSET_CDATA + p1), p1);
PM.check(PM.TRAP_INT_ADD_3);
num_add_1.add(num_add_2);
PM.check(PM.TRAP_INT_ADD_4);
short len = num_add_1.toByteArray(apdubuf, (short) 0);
apdu.setOutgoingAndSend((short) 0, len);
}
示例6: test_EC_SETCURVE_G
import javacard.framework.APDU; //导入方法依赖的package包/类
void test_EC_SETCURVE_G(APDU apdu, short dataLen) {
byte[] apdubuf = apdu.getBuffer();
Util.arrayCopyNonAtomic(apdubuf, ISO7816.OFFSET_CDATA, m_customG, (short) 0, dataLen);
PM.check(PM.TRAP_EC_SETCURVE_1);
if (apdubuf[ISO7816.OFFSET_P2] == 1) { // If required, complete new custom curve and point is allocated
m_testCurveCustom = new ECCurve(false, SecP256r1.p, SecP256r1.a, SecP256r1.b, m_customG, SecP256r1.r, m_ecc);
m_testPointCustom = new ECPoint(m_testCurveCustom, m_ecc);
PM.check(PM.TRAP_EC_SETCURVE_2);
// Release unused previous objects
if (!bIsSimulator) {
JCSystem.requestObjectDeletion();
}
}
else {
// Otherwise, only G is set and relevant objects are updated
m_testCurveCustom.setG(apdubuf, (short) ISO7816.OFFSET_CDATA, m_testCurveCustom.POINT_SIZE);
m_testPointCustom.updatePointObjects(); // After changing curve parameters, internal objects needs to be actualized
}
}
示例7: test_INT_MUL
import javacard.framework.APDU; //导入方法依赖的package包/类
void test_INT_MUL(APDU apdu, short dataLen) {
byte[] apdubuf = apdu.getBuffer();
short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);
PM.check(PM.TRAP_INT_MUL_1);
Integer num_mul_1 = m_testINT1;
num_mul_1.fromByteArray(apdubuf, ISO7816.OFFSET_CDATA, p1);
Integer num_mul_2 = m_testINT2;
num_mul_2.fromByteArray(apdubuf, (short) (ISO7816.OFFSET_CDATA + p1), p1);
PM.check(PM.TRAP_INT_MUL_2);
num_mul_1.multiply(num_mul_2);
PM.check(PM.TRAP_INT_MUL_3);
short len = num_mul_1.toByteArray(apdubuf, (short) 0);
apdu.setOutgoingAndSend((short) 0, len);
}
示例8: test_BN_SUB
import javacard.framework.APDU; //导入方法依赖的package包/类
void test_BN_SUB(APDU apdu, short dataLen) {
byte[] apdubuf = apdu.getBuffer();
short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);
PM.check(PM.TRAP_BN_SUB_1);
Bignat sub1 = m_testBN1;
sub1.set_size(p1);
PM.check(PM.TRAP_BN_SUB_2);
Bignat sub2 = m_testBN2;
sub2.set_size((short) (dataLen - p1));
PM.check(PM.TRAP_BN_SUB_3);
Bignat result = m_testBN3;
result.set_size((short) (p1 + 1));
PM.check(PM.TRAP_BN_SUB_4);
sub1.from_byte_array(dataLen, (short)0, apdubuf, ISO7816.OFFSET_CDATA);
sub2.from_byte_array(dataLen, (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1));
PM.check(PM.TRAP_BN_SUB_5);
result.copy(sub1);
PM.check(PM.TRAP_BN_SUB_6);
result.subtract(sub2);
PM.check(PM.TRAP_BN_SUB_7);
short len = result.copy_to_buffer(apdubuf, (short) 0);
apdu.setOutgoingAndSend((short) 0, len);
}
示例9: test_BN_INV_MOD
import javacard.framework.APDU; //导入方法依赖的package包/类
void test_BN_INV_MOD(APDU apdu, short dataLen) {
byte[] apdubuf = apdu.getBuffer();
short p1 = (short) (apdubuf[ISO7816.OFFSET_P1] & 0x00FF);
PM.check(PM.TRAP_BN_INV_MOD_1);
Bignat num1 = m_testBN1;
num1.set_size(p1);
PM.check(PM.TRAP_BN_INV_MOD_2);
Bignat mod = m_testBN2;
mod.set_size((short) (dataLen - p1));
PM.check(PM.TRAP_BN_INV_MOD_3);
num1.from_byte_array(p1, (short)0, apdubuf, ISO7816.OFFSET_CDATA);
mod.from_byte_array((short)(dataLen-p1), (short)0, apdubuf, (short)(ISO7816.OFFSET_CDATA+p1));
PM.check(PM.TRAP_BN_INV_MOD_4);
num1.mod_inv(mod);
PM.check(PM.TRAP_BN_INV_MOD_5);
short len = num1.copy_to_buffer(apdubuf, (short) 0);
apdu.setOutgoingAndSend((short) 0, len);
}
示例10: readAPDU
import javacard.framework.APDU; //导入方法依赖的package包/类
public static short readAPDU(APDU apdu, byte[] buffer, short length) {
short read = apdu.setIncomingAndReceive();
read += apdu.getOffsetCdata();
short total = apdu.getIncomingLength();
if (total > length) {
return 0;
}
byte[] apduBuffer = apdu.getBuffer();
short sum = 0;
do {
Util.arrayCopyNonAtomic(apduBuffer, (short) 0, buffer, sum, read);
sum += read;
read = apdu.receiveBytes((short) 0);
} while (sum < total);
return 0;
}
示例11: process
import javacard.framework.APDU; //导入方法依赖的package包/类
public void process(APDU apdu) {
// Good practice: Return 9000 on SELECT
if (selectingApplet()) {
return;
}
byte[] incomingBuf = apdu.getBuffer();
short length = apdu.setIncomingAndReceive();
if(!usChannel.isSessionSecure()){
usChannel.establishSecureSession(apdu, incomingBuf);
}else{
if(incomingBuf[ISO7816.OFFSET_INS] == 0x20){
usChannel.resetSessionState();
}else{
short decodedLC = usChannel.decodeIncoming(apdu, incomingBuf, length);
if(decodedLC > 0){
usChannel.encodeAndSend(apdu, incomingBuf, ISO7816.OFFSET_CDATA, (short)(incomingBuf[ISO7816.OFFSET_LC] & 0x00FF));
}
}
}
}
示例12: process
import javacard.framework.APDU; //导入方法依赖的package包/类
public void process(APDU apdu) throws ISOException {
if (selectingApplet())
return;
byte[] buffer = apdu.getBuffer();
switch (buffer[ISO7816.OFFSET_CLA]) {
case (byte) 0x00: // ISO as described in specs
case (byte) 0x10: // Chaining
process_real_commands(apdu, buffer);
break;
case (byte) 0x80: // Proprietary: setting/getting values
process_mock_commands(apdu, buffer);
break;
default:
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
break;
}
}
示例13: storeVariableLength
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* Store the incoming APDU data in a fixed buffer, the first byte will contain the data length.
*
* @param pin_type indicates which PIN should be checked.
*/
void storeVariableLength(APDU apdu, byte[] destination, short pin_type) {
byte[] buffer = apdu.getBuffer();
// When writing DOs, PW1 really means PW1 submitted as PW2.
if (!pins[pin_type].isValidated() ||
((pin_type == PIN_INDEX_PW1) && !pinSubmitted[1])) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
short length = (short) (buffer[ISO7816.OFFSET_LC] & 0x00FF);
if ((short) (length + 1) > destination.length || length > (short) 255 ||
apdu.setIncomingAndReceive() != length) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
JCSystem.beginTransaction();
destination[0] = (byte) length;
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, destination, (short) 1, length);
JCSystem.commitTransaction();
}
示例14: storeFixedLength
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* Store the fixed length incoming APDU data in a buffer. If the APDU data length is less than the
* maximum length, the data will be padded with zeroes.
*/
void storeFixedLength(APDU apdu, byte[] destination, short offset, short maximum_length) {
byte[] buffer = apdu.getBuffer();
// When writing DOs, PW1 really means PW1 submitted as PW2.
if (!pins[PIN_INDEX_PW3].isValidated()) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
short length = (short) (buffer[ISO7816.OFFSET_LC] & 0x00FF);
if (length > maximum_length || apdu.setIncomingAndReceive() != length) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, destination, offset, length);
if (maximum_length > length) {
Util.arrayFillNonAtomic(destination, (short) (offset + length),
(short) (maximum_length - length), (byte) 0);
}
}
示例15: internalAuthenticate
import javacard.framework.APDU; //导入方法依赖的package包/类
private void internalAuthenticate(APDU apdu) {
byte[] buffer = apdu.getBuffer();
// PW1 with 0x82
if (!pins[PIN_INDEX_PW1].isValidated() || !pinSubmitted[1]) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
short len = apdu.setIncomingAndReceive();
if (len > (short) 102 || len != (buffer[ISO7816.OFFSET_LC] & 0xFF)) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
if (!authenticationKey.getPrivate().isInitialized()) {
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
}
cipherRSA.init(authenticationKey.getPrivate(), Cipher.MODE_ENCRYPT);
cipherRSA.doFinal(buffer, ISO7816.OFFSET_CDATA, len, buffer, (short) 0);
apdu.setOutgoingAndSend((short) 0, RSA_KEY_LENGTH_BYTES);
}