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 set EC parameters of Keypair

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

How to set EC parameters of Keypair

Post by 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: 35
Joined: Wed Jun 20, 2018 4:06 am
Points :218
Contact:

Re: How to set EC parameters of Keypair

Post by 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: 53
Joined: Mon Jun 04, 2018 5:07 am
Points :392
Contact:

Re: How to set EC parameters of Keypair

Post by 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: 39
Joined: Wed Aug 31, 2016 9:55 pm
Points :372
Contact:

Re: How to set EC parameters of Keypair

Post by 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: 53
Joined: Mon Jun 04, 2018 5:07 am
Points :392
Contact:

Re: How to set EC parameters of Keypair

Post by DaHuFa » Sun Jul 15, 2018 11:49 pm

It works! Thank you very much~

BirdKing
Posts: 86
Joined: Wed Nov 04, 2015 7:23 am
Points :656
Contact:

Re: How to set EC parameters of Keypair

Post by BirdKing » Wed Oct 31, 2018 2:56 am

If you call KeyPair() as KeyPair(KeyPair.ALG_EC_FP, keyLen), the encapsulated keys are uninitialized. Then genKeyPair() will initialize the key with default paramters.
If you call KeyPair() as KeyPair(pubKey, priKey), the encapsulated keys will be initialized with the parameters of pubKey.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 47 guests

JavaCard OS : Disclaimer