Page 1 of 1

Got 6E00 when implementing RSA encryption

Posted: Tue Dec 01, 2015 2:43 am
by lostsiwonlw
I am writing a javacard applet. RSA public and private keys are generated in constructor.

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.

Re: Got 6E00 when implementing RSA encryption

Posted: Wed Dec 02, 2015 8:51 am
by predators
You can using try{...} catch(){...} to get the reason of this error.
such as

Code: Select all

try
      {
         length = cipher.doFinal(, , , );
      }
      catch(CryptoException e)
      {
         short i = e.getReason();
      }

Re: Got 6E00 when implementing RSA encryption

Posted: Thu Dec 03, 2015 1:14 am
by UNKNwYSHSA
6E00 means the CLA not supported.
What is the APDU command you sent?