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.

Get CryptoException.ILLEGAL_VALUE when generating ECC key pair

Card Products

Moderator: horse dream

Jsine
Posts: 10
Joined: Mon Mar 14, 2016 5:12 am
Points :106
Contact:

Get CryptoException.ILLEGAL_VALUE when generating ECC key pair

Post by Jsine » Mon Mar 14, 2016 5:20 am

Hi everyone!
Today I used JCOP card to generate ECC key pair. I can create ECPrivateKey, ECPublicKey, KeyPair w/o any problems, but it throws exception CryptoException.ILLEGAL_VALUE when genKeyPair(). What's wrong with my card or my operation? I have no idea. Could you please tell me where I made the mistake? Much appreciated!

BTW, I found that JCAlgTest has encountered the same problem, pls check the test report here.

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

Re: Get CryptoException.ILLEGAL_VALUE when generating ECC key pair

Post by horse dream » Wed Mar 16, 2016 11:27 pm

For JCOP card, you should set ECC domain parameters for both the public key and private key before genKeyPair().

FYI:
Check the code below to set the parameters.

Code: Select all

pubKey.setFieldFP(p, (short) 0, (short) p.length);
pubKey.setA(a, (short) 0, (short) a.length);
pubKey.setB(b, (short) 0, (short) b.length);
pubKey.setG(g, (short) 0, (short) g.length);
pubKey.setR(n, (short) 0, (short) n.length);
pubKey.setK((short) 1);
priKey.setFieldFP(p, (short) 0, (short) p.length);
priKey.setA(a, (short) 0, (short) a.length);
priKey.setB(b, (short) 0, (short) b.length);
priKey.setG(g, (short) 0, (short) g.length);
priKey.setR(n, (short) 0, (short) n.length);
priKey.setK((short) 1);

Jsine
Posts: 10
Joined: Mon Mar 14, 2016 5:12 am
Points :106
Contact:

Re: Get CryptoException.ILLEGAL_VALUE when generating ECC key pair

Post by Jsine » Wed Mar 16, 2016 11:38 pm

horse dream wrote:For JCOP card, you should set ECC domain parameters for both the public key and private key before genKeyPair().

FYI:
Check the code below to set the parameters.

Code: Select all

pubKey.setFieldFP(p, (short) 0, (short) p.length);
pubKey.setA(a, (short) 0, (short) a.length);
pubKey.setB(b, (short) 0, (short) b.length);
pubKey.setG(g, (short) 0, (short) g.length);
pubKey.setR(n, (short) 0, (short) n.length);
pubKey.setK((short) 1);
priKey.setFieldFP(p, (short) 0, (short) p.length);
priKey.setA(a, (short) 0, (short) a.length);
priKey.setB(b, (short) 0, (short) b.length);
priKey.setG(g, (short) 0, (short) g.length);
priKey.setR(n, (short) 0, (short) n.length);
priKey.setK((short) 1);


@horse dream, thanks for your detailed reply! I have solved my problem according to your answer!

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 24 guests

JavaCard OS : Disclaimer