Problem with ECC
Posted: Wed Sep 12, 2018 4:56 am
Hi, guys. I have written some code for signing messages by ECDSA algorithm. But JavaCard returns me every time different values with different sizes.
For example:
I need to get { s, r } values, but getting this. How to parse it? (Sorry for my English)
My code
Thanks, for help!
For example:
Code: Select all
30450221008443B0B08EACBF7B4F718AF441154CE79391AC2206715A13950DBDF65E2004A2022041C8086F556D4BD4F5B0B87412A3982F75C12447901886BE01F0EBC44C937B2E
My code
Code: Select all
private void processSign(APDU apdu) {
byte[] apduBuffer = apdu.getBuffer();
apdu.setIncomingAndReceive();
try {
privateKey.setS(privateKeyDigest, (short) 0, PRIVATE_KEY_LENGTH);
signature.init(privateKey, Signature.MODE_SIGN);
byte[] tempBuffer = JCSystem.makeTransientByteArray(SIGN_BUFFER_LENGTH, JCSystem.CLEAR_ON_DESELECT);
short len = signature.sign(hashDigest, (short) 0, HASH_LENGTH, tempBuffer, SIGN_BUFFER_OFFSET);
Util.arrayCopyNonAtomic(tempBuffer, (short) 0, apduBuffer, (short) 0, len);
apdu.setOutgoingAndSend((short) 0, len);
} catch (CryptoException e) {
ISOException.throwIt(e.getReason());
} catch (SystemException e) {
ISOException.throwIt(e.getReason());
}
}
Thanks, for help!