我是Java Card的全部主题的新手,并试图查看一些代码示例以便更好地理解.我在oracle论坛中找到了一个AES使用示例,但是在以下部分遇到了一些问题:
private void doAES(APDU apdu)
{
byte b[] = apdu.getBuffer();
short incomingLength = (short) (apdu.setIncomingAndReceive());
if (incomingLength != 24) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
//perform encryption and append results in APDU Buffer a[] automatically
cipherAES.init(aesKey, Cipher.MODE_ENCRYPT);
cipherAES.doFinal(b, (short) dataOffset, incomingLength, a, (short) (dataOffset + 24));
cipherAES.init(aesKey, Cipher.MODE_DECRYPT);
cipherAES.doFinal(b, (short) (dataOffset + 24), incomingLength, a, (short) (dataOffset + 48));
// Send results
apdu.setOutgoing();
apdu.setOutgoingLength((short) 72);
apdu.sendBytesLong(b, (short) dataOffset, (short) 72);
}
Run Code Online (Sandbox Code Playgroud)
根据我的理解,此代码从传入的APDU获取前24个数据字节,对它们进行加密并将它们放入字节数组a中.然后它接下来的24个数据字节,解密它们并将它们放入其中.
但是以下命令不使用这些输出数据
apdu.sendBytesLong(b, (short) dataOffset, (short) 72);
Run Code Online (Sandbox Code Playgroud)
使用b作为输出数据...这可能不正确所以请帮助我理解我哪里出错了.
另外:用这个和相应答案加密小文本的简单命令APDU是什么样的?