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