JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html

reconstruct an ECPublicKey from JavaCard to Java

Algorithm School

Moderator: UNKNwYSHSA

User avatar
Peterson
Posts: 2
Joined: Wed May 20, 2015 3:57 am
Points :0
Contact:

reconstruct an ECPublicKey from JavaCard to Java

Post by Peterson » Tue Jun 23, 2015 6:06 am

I need to implement ECDH between a terminal side and a java card side.

Code: Select all

 ECPublicKey pubKey = (ECPublicKey) KeyBuilder.buildKey(
            KeyBuilder.TYPE_EC_FP_PUBLIC, (short) 0x0100, false);
        pubKey.setFieldFP(p, (short) 0x0001, (short) 0x0020);
        pubKey.setA(a, (short) 0x0001, (short) 0x0020);
        pubKey.setB(b, (short) 0x0000, (short) 0x0020);
        pubKey.setR(r, (short) 0x0001, (short) 0x0020);
        pubKey.setG(g, (short) 0x0000, (short) g.length);

        ECPrivateKey privKey = (ECPrivateKey) KeyBuilder.buildKey(
            KeyBuilder.TYPE_EC_FP_PRIVATE, (short) 0x0100, false);

        KeyPair keypair = new KeyPair(pubKey, privKey);
        keypair.genKeyPair();

        pubKey.getW(apduBuffer, (short) 0x0000);
        setOutgoingAndSend((short) 0x0000, (short) 0x0041);

On the card side, the code above is performed .
I generate a KeyPair for ECDH,and send the the public one to the terminal side.

But i can't use java to reconstruct an ECPublicKey provided the response APDU I get.
What can i do? Could anyone give me any clues?Thanks a lot.

User avatar
horse dream
Posts: 76
Joined: Thu May 21, 2015 11:48 pm
Points :140
Contact:

Re: reconstruct an ECPublicKey from JavaCard to Java

Post by horse dream » Tue Jun 23, 2015 6:16 am

The ECPublicKey 's format returned in JavaCard is as follows: 04 x y. On the terminal side, you should extract x and y coordinates first.

Code: Select all

KeyFactory kf = KeyFactory.getInstance("ECDSA", "BC");
ECPoint point = new ECPoint(x, y);
ECParameterSpec domainparameters = new ECParameterSpec(...); // initialize your domain parameters
ECPublicKeySpec spec = new ECPublicKeySpec(point, domainparameters);
ECPublicKey publickey = (ECPublicKey)kf.generatePublic(spec);

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 59 guests

JavaCard OS : Disclaimer