It's our great honour to announce the Industry’s First VHBR CCID reader - VHBR Dual interface smart card reader vR504. It is able to support the world’s fastest ePassports.

To celebrate the new product release, there is Special Discount for New Registered Members in our store.
- Get $20.00 OFF instantly for smart card reader vR504, R502 and bR301

Come to get the readers now!

How to set EC parameters of Keypair

JavaCard Applet Development Related Questions and Answers.
DaHuFa
Posts: 14
Joined: Mon Jun 04, 2018 5:07 am
Points: 100
Contact:

How to set EC parameters of Keypair

Postby DaHuFa » Fri Jul 13, 2018 5:03 am

hello, everyone.
I have a problem with KeyPair. I want generate a EC keypair with KeyPair.genKeyPair(). And I hope the EC components parameters is my indicated parameters. But I not know how to set those parameters. Who can help me?

happy123654
Posts: 11
Joined: Wed Jun 20, 2018 4:06 am
Points: 70
Contact:

Re: How to set EC parameters of Keypair

Postby happy123654 » Fri Jul 13, 2018 5:10 am

You can set the parameter via the API :setA; setB; setG; setR; setK;setFieldFP;setFieldF2M.
If you don't set the parameter into the card cos. the cos may use the default parameter.

DaHuFa
Posts: 14
Joined: Mon Jun 04, 2018 5:07 am
Points: 100
Contact:

Re: How to set EC parameters of Keypair

Postby DaHuFa » Fri Jul 13, 2018 5:22 am

You can set the parameter via the API :setA; setB; setG; setR; setK;setFieldFP;setFieldF2M.
If you don't set the parameter into the card cos. the cos may use the default parameter.


Thank for your answer very much. I try this way your mentioned. But the parameters is still not my expected.
My applet is:

Code: Select all

if((short)256 == keyLen){
         key.setA(SECP256R1_A, (short)0, (short)SECP256R1_A.length);
         key.setB(SECP256R1_B, (short)0, (short)SECP256R1_B.length);
         key.setFieldFP(SECP256R1_FP, (short)0, (short)SECP256R1_FP.length);
         key.setG(SECP256R1_G, (short)0, (short)SECP256R1_G.length);
         key.setR(SECP256R1_R, (short)0, (short)SECP256R1_R.length);
              }
             
short keyLen = Util.makeShort(buf[ISO7816.OFFSET_P1], buf[ISO7816.OFFSET_P2]);
         try{
            ecPair = new KeyPair(KeyPair.ALG_EC_FP, keyLen);
         }catch(CryptoException e)
         {
            ISOException.throwIt((short)(0x6900 + e.getReason()));
         }

scplatform
Posts: 8
Joined: Wed Aug 31, 2016 9:55 pm
Points: 178
Contact:

Re: How to set EC parameters of Keypair

Postby scplatform » Sat Jul 14, 2018 9:36 pm

You should set ECC parameters before call genKeyPair(), as the description of jcapi v2.2.2, just need to set the public key parameters, and then, call genKeyPair(), e.g:

Code: Select all

ECPrivateKey priKey = new ECPrivateKeyImpl(KeyBuilder.ALG_TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_256, JCSystem.MEMORY_TYPE_PERSISTENT);
      ECPublicKey pubKey = new ECPublicKeyImpl(KeyBuilder.ALG_TYPE_EC_FP_PUBLIC, KeyBuilder.LENGTH_EC_FP_256, JCSystem.MEMORY_TYPE_PERSISTENT);
      pubKey.setA(SECP256R1_A, (short)0, (short)SECP256R1_A.length);
      pubKey.setB(SECP256R1_B, (short)0, (short)SECP256R1_B.length);
      pubKey.setFieldFP(SECP256R1_FP, (short)0, (short)SECP256R1_FP.length);
      pubKey.setG(SECP256R1_G, (short)0, (short)SECP256R1_G.length);
      pubKey.setR(SECP256R1_R, (short)0, (short)SECP256R1_R.length);
      pubKey.setK(cofactor);
      KeyPair kp = new KeyPair(pubKey, priKey);
      kp.genKeyPair();//You can get the pubkey and private key

DaHuFa
Posts: 14
Joined: Mon Jun 04, 2018 5:07 am
Points: 100
Contact:

Re: How to set EC parameters of Keypair

Postby DaHuFa » Sun Jul 15, 2018 11:49 pm

It works! Thank you very much~


Return to “Questions & Answers”

Who is online

Users browsing this forum: No registered users and 0 guests

JavaCard OS : Disclaimer