Code: Select all
public RSAApplet() {
keyPair = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048);
keyPair.genKeyPair();
rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();
rsaPublicKey = (RSAPublicKey) keyPair.getPublic();
cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
register();
}
Main method code:
Code: Select all
private void encryptData(APDU apdu) {
if (!rsaPublicKey.isInitialized()) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
byte[] apduBuffer = apdu.getBuffer();
apdu.setIncomingAndReceive();
cipher.init(rsaPrivateKey, Cipher.MODE_ENCRYPT);
byte[] encryptedBuffer = new byte[apduBuffer.length];
Util.arrayFillNonAtomic(encryptedBuffer, (short) 0,
(short) encryptedBuffer.length, (byte) 0xAA);
cipher.doFinal(encryptedBuffer, (short) 0, (short) encryptedBuffer.length, apduBuffer, (short) 0);
// Just for testing send 120 bytes
apdu.setOutgoingAndSend((short) 0, (short) 120);
}
When I install applet into my javacard, it returns sw=6E00.
I guess the problem may occur when cipher.doFinal() is executing. But I don't know the details about what is going on.
Could anybody help me determin the problem? Any help is greatly appreciated.