Skip to Main Content

Java Card

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Signing using ECDSA

1022375Jul 19 2013 — edited Jul 22 2013

I am trying to generate a KeyPair and sign using ECDSA, but am running into problems.

I am trying to make key size of length 256, so this is the code I want to use:

KeyPair keys = null;

Signature sig;

MessageDigest hash;

byte[] hashArray = new byte[32];

byte[] sigOutput = new byte[56];

if (keys == null) {

     // CREATE ECDSA KEYPAIR

     keys =  new KeyPair(KeyPair.ALG_EC_FP, KeyBuilder.LENGTH_EC_FP_256);

     // START ON CARD KEY GENERATION PROCESS

     keys.genKeyPair();

}

// CREATE SIGNATURE OBJECT

sig = Signature.getInstance(Signature.ALG_ECDSA_SHA_256, false);

// INITIALIZE WITH PRIVATE KEY

sig.init(keys.getPrivate(), Signature.MODE_SIGN);

// SIGN INCOMING BUFFER

sig.sign(sigInput, (short) 0, (short) sigInput.length, sigOutput, (short) 0);


But for some reason, it always fails when I try to build a new KeyPair. However, if I use either:

keys = new KeyPair(KeyPair.ALG_EC_FP, KeyBuilder.LENGTH_EC_FP_192); or

keys = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_512)

it works fine.


I am using Java Card simulator in netbeans, not an actual card; is that the problem (sim might not support those functions)?


Thanks for the help

This post has been answered by _emerson on Jul 19 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 19 2013
Added on Jul 19 2013
4 comments
1,560 views