In order to thank you for all members' support of our website, we are holding new events - Getting Free Samples by Paying Freight only.
Want to get free samples? Please check this post for more details.

How to set EC parameters of Keypair

JavaCard Applet Development Related Questions and Answers.
DaHuFa
Posts: 27
Joined: Mon Jun 04, 2018 5:07 am
Points :190
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: 19
Joined: Wed Jun 20, 2018 4:06 am
Points :98
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: 27
Joined: Mon Jun 04, 2018 5:07 am
Points :190
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: 29
Joined: Wed Aug 31, 2016 9:55 pm
Points :268
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: 27
Joined: Mon Jun 04, 2018 5:07 am
Points :190
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~

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 1 guest

JavaCard OS : Disclaimer