JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html
https://ftsafe.en.alibaba.com/index.html
How to set EC parameters of Keypair
How to set EC parameters of Keypair
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?
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?
-
- Posts: 35
- Joined: Wed Jun 20, 2018 4:06 am
- Points :218
- Contact:
Re: How to set EC parameters of Keypair
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.
If you don't set the parameter into the card cos. the cos may use the default parameter.
Re: How to set EC parameters of Keypair
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()));
}
-
- Posts: 39
- Joined: Wed Aug 31, 2016 9:55 pm
- Points :372
- Contact:
Re: How to set EC parameters of Keypair
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
Re: How to set EC parameters of Keypair
It works! Thank you very much~
Re: How to set EC parameters of Keypair
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.
If you call KeyPair() as KeyPair(pubKey, priKey), the encapsulated keys will be initialized with the parameters of pubKey.
Who is online
Users browsing this forum: No registered users and 39 guests