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.

How to send public key to host application

Algorithm School

Moderator: UNKNwYSHSA

JCaberham
Posts: 26
Joined: Mon Nov 30, 2015 3:02 am
Points :208
Contact:

How to send public key to host application

Post by JCaberham » Thu Dec 24, 2015 5:47 am

I am using RSA algorithm to create public/private key in my application. Now I want to send the public key to host application. Could any one please help me about how to implement this? Thanks for any answers.

Code: Select all

keys = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048);
        keys.genKeyPair();
        rsa_publicKey = (RSAPublicKey) keys.getPublic();

Bob2002
Posts: 36
Joined: Wed Jul 29, 2015 10:50 pm
Points :1218
Contact:

Re: How to send public key to host application

Post by Bob2002 » Thu Dec 24, 2015 10:53 pm

This projectwill helpful

some code like

Code: Select all

/**
     * Generate an assymetric RSA key pair according to ISO7816-8,
     * Section 5.1. We only support RSA 1024 bit at the moment, and
     * return data in simple TLV data objects, tags 81 and 82.
     *
     * Successful MSE command has to be performed prior to this one.
     */
    private void processGenerateAssymetricKeyPair(APDU apdu) {
        // This is only valid in state initial (at the moment)
        if(state != STATE_INITIAL) {
            ISOException.throwIt(SW_INS_NOT_SUPPORTED);
        }
        byte[] buf = apdu.getBuffer();
        byte p1 = buf[OFFSET_P1];
        byte p2 = buf[OFFSET_P2];
        if(p1 != (byte)0x80 || p2 != (byte)0x00) {
            ISOException.throwIt(SW_INCORRECT_P1P2);
        }
        if(currentPrivateKey[0] == null) {
            ISOException.throwIt(SW_CONDITIONS_NOT_SATISFIED);
        }
        KeyPair pair = new KeyPair(tempKeyPublic, (RSAPrivateCrtKey)currentPrivateKey[0]);
        pair.genKeyPair();
        // Sanity check, the KeyPair class should regenerate the keys "in place".
        if(pair.getPrivate() != currentPrivateKey[0] || pair.getPublic() != tempKeyPublic) {
            ISOException.throwIt(SW_DATA_INVALID);
        }
        apdu.setOutgoing();
        short len = (short)0;
        short offset = 0;
        buf[offset++] = (byte)0x81;
        len = tempKeyPublic.getModulus(buf, (short)(offset+2));
        buf[offset++] = (byte)0x81;
        buf[offset++] = (byte)len;
        offset += len;
        buf[offset++] = (byte)0x82;
        len = tempKeyPublic.getExponent(buf, (short)(offset+1));
        buf[offset++] = (byte)len;
        offset += len;
        apdu.setOutgoingLength(offset);
        apdu.sendBytes((short)0, offset);
    }

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 13 guests

JavaCard OS : Disclaimer