Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

6C XX Unknown Error

JavaCard Applet Development Related Questions and Answers.
keiji
Posts: 3
Joined: Tue Dec 13, 2016 8:45 pm
Points :72
Contact:

6C XX Unknown Error

Post by keiji » Tue Jan 03, 2017 10:08 pm

Hi, im having a problem with this error.
I tried changing the Le since it said that 6C XX error comes from Le but the error still there.
This is the source code.

Code: Select all

import javacard.framework.*;
import javacard.security.*;
import javacardx.crypto.*;

public class ECDSA extends Applet
{
   private byte[] plaintext ;
    private ECPrivateKey  objECDSAPriKey=null;    // Object for ECDSA Private Key
    private ECPublicKey   key=null;               // Object for ECDSA Public Key
    private KeyPair       objECDSAKeyPair=null;   // Object for ECDSA Key Pair
    private Signature     objECDSASign=null;
   
    final static short  BAS  =  0;
   
   private final static byte[] fp = new byte[] {
        (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
        (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
        (byte)0xFF, (byte)0xFE, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
        (byte)0xFF, (byte)0xFF, (byte)0xFF };
    private final static byte[] r = new byte[] {
        (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
        (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x99, (byte)0xDE,
        (byte)0xF8, (byte)0x36, (byte)0x14, (byte)0x6B, (byte)0xC9, (byte)0xB1, (byte)0xB4,
        (byte)0xD2, (byte)0x28, (byte)0x31 };
    private final static byte[] a = new byte[] {
        (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
        (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
        (byte)0xFF, (byte)0xFE, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
        (byte)0xFF, (byte)0xFF, (byte)0xFC };
    private final static byte[] b = new byte[] {
        (byte)0x64, (byte)0x21, (byte)0x05, (byte)0x19, (byte)0xE5, (byte)0x9C, (byte)0x80,
        (byte)0xE7, (byte)0x0F, (byte)0xA7, (byte)0xE9, (byte)0xAB, (byte)0x72, (byte)0x24,
        (byte)0x30, (byte)0x49, (byte)0xFE, (byte)0xB8, (byte)0xDE, (byte)0xEC, (byte)0xC1,
        (byte)0x46, (byte)0xB9, (byte)0xB1 };
    private final static byte[] g = new byte[] {
        (byte)0x04, (byte)0x18, (byte)0x8D, (byte)0xA8, (byte)0x0E, (byte)0xB0, (byte)0x30,
        (byte)0x90, (byte)0xF6, (byte)0x7C, (byte)0xBF, (byte)0x20, (byte)0xEB, (byte)0x43,
        (byte)0xA1, (byte)0x88, (byte)0x00, (byte)0xF4, (byte)0xFF, (byte)0x0A, (byte)0xFD,
        (byte)0x82, (byte)0xFF, (byte)0x10, (byte)0x12, (byte)0x07, (byte)0x19, (byte)0x2B,
        (byte)0x95, (byte)0xFF, (byte)0xC8, (byte)0xDA, (byte)0x78, (byte)0x63, (byte)0x10,
        (byte)0x11, (byte)0xED, (byte)0x6B, (byte)0x24, (byte)0xCD, (byte)0xD5, (byte)0x73,
        (byte)0xF9, (byte)0x77, (byte)0xA1, (byte)0x1E, (byte)0x79, (byte)0x48, (byte)0x11 }; //49
     private final static short k = 1;   
     
    public static void install(byte[] bArray, short bOffset, byte bLength){
    new ECDSA(bArray, bOffset, bLength);
    }
   
    private ECDSA(byte bArray[], short bOffset, byte bLength){   

    plaintext = new byte[0x50] ;         

    Util.arrayFillNonAtomic(plaintext, BAS, (short)0x50, (byte)0);

    register();
    }
     
    public void process(APDU apdu){
    byte buf[] = apdu.getBuffer();
     
     switch(buf[1])
    {
        case (byte)0xA4:
           break;
           
       case (byte)0x46:
         
     objECDSAPriKey = (ECPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_192, false);
      //ISOException.throwIt((short)0x8888);       
      key = (ECPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC,  KeyBuilder.LENGTH_EC_FP_192, false);
       
        key.setFieldFP(fp, (short)0, (short)fp.length);
        key.setR(r, (short)0, (short)r.length);
        key.setA(a, (short)0, (short)a.length);
        key.setB(b, (short)0, (short)b.length);
        key.setG(g, (short)0, (short)g.length);
        key.setK(k);
       
     objECDSAKeyPair = new KeyPair(KeyPair.ALG_EC_FP, KeyBuilder.LENGTH_EC_FP_192);

    // On-Card Key Generation Process
      objECDSAKeyPair.genKeyPair();

     // Obtain Key References
      objECDSAPriKey = (ECPrivateKey)objECDSAKeyPair.getPrivate();
      key = (ECPublicKey)objECDSAKeyPair.getPublic(); 

     // Create Signature Object
      objECDSASign = Signature.getInstance(Signature.ALG_ECDSA_SHA, false);
     
      break;
     
       case (byte)0x2E:   
          
              short   sSignLen = 0;
            short   Le = apdu.setOutgoing();   
                   
            // Init with Private Key
            objECDSASign.init(objECDSAPriKey, Signature.MODE_SIGN);
         
           // Sign Data
           sSignLen = objECDSASign.sign(plaintext, BAS, Le, buf, BAS); //(byte[], short, short, byte[])
                 
            apdu.setOutgoingLength(sSignLen);
            apdu.sendBytes(BAS, sSignLen);
           
     default:
            ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    }

    return;
    }
}


Please help me figure out this thing and thank you very much in advance you guys are my hero.
You do not have the required permissions to view the files attached to this post. Please login first.

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: 6C XX Unknown Error

Post by UNKNwYSHSA » Wed Jan 04, 2017 1:16 am

Look comment for each code line:

Code: Select all

       case (byte)0x2E:
         // Normally, the APDU buffer size is 261, so this method can receive data to most 255 bytes;
         short dataLen = apdu.setIncomingAndReceive();

         // Init with Private Key
         objECDSASign.init(objECDSAPriKey, Signature.MODE_SIGN);

         // Sign Data
         // Input data is in the APDU buffer;
         // And the APDU buffer can be used as output buffer;
         short sSignLen = objECDSASign.sign(buf, BAS, (short) (buf[ISO7816.OFFSET_LC] & 0xFF), buf, BAS); //(byte[], short, short, byte[])
         
         // Sent signature result data;
         apdu.setOutgoingAndSend((short) 0, sSignLen);
         
         // Break at the end of each INS;
         break;
     default:
            ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
sense and simplicity

keiji
Posts: 3
Joined: Tue Dec 13, 2016 8:45 pm
Points :72
Contact:

Re: 6C XX Unknown Error

Post by keiji » Wed Jan 04, 2017 7:02 am

Thank you @UNKNwYSHSA you are very kind may you find happiness in life :D

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: 6C XX Unknown Error

Post by UNKNwYSHSA » Wed Jan 04, 2017 11:36 am

:lol:
sense and simplicity

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 98 guests

JavaCard OS : Disclaimer