Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

how to make a signature with java card and verify it

Algorithm School

Moderator: UNKNwYSHSA

User avatar
btwtiger
Posts: 28
Joined: Wed Jun 10, 2015 7:22 am
Points :134
Contact:

how to make a signature with java card and verify it

Post by btwtiger » Thu Nov 19, 2015 8:16 am

I encountered a problem when handling the signature generation and verification. Hope s.b. give me any advice.

Code: Select all

SignatureMessageRecovery sig;

...

private Cardlet(byte[] bArray, short bOffset, byte bLength) {
    /* Generate our RSA key */
    keyPair = new KeyPair(KeyPair.ALG_RSA, (short) 512);
    keyPair.genKeyPair();
    /* signature buffer is 64 + 2 (offset + length) */
    sigBuff = JCSystem.makeTransientByteArray((short) (SIG_LENGTH + 2), JCSystem.CLEAR_ON_DESELECT);
    sig = (SignatureMessageRecovery) Signature.getInstance(Signature.ALG_RSA_SHA_ISO9796_MR, false);
}

...

private void insCryptoSigne(APDU apdu) {

    byte[] buffer = apdu.getBuffer();
    short bytesRead = apdu.setIncomingAndReceive();
    short[] m1Data = JCSystem.makeTransientShortArray((short) 1, JCSystem.CLEAR_ON_DESELECT);

    sigLen = sig.sign(buffer, ISO7816.OFFSET_CDATA, bytesRead, sigBuff, (short) 0, m1Data, (short) 0);
    // set m1Length into sigBuff array
    sigBuff[sigLen] = (byte) ((short) (m1Data[(short) 0] & ((short) 0xFF00)) >> ((short) 8));
    sigBuff[(short) (sigLen + 1)] = (byte) (m1Data[(short) 0] & ((short) 0x00FF));

    apdu.setOutgoing();
    apdu.setOutgoingLength((short) (sigLen + 2));// The extra 2 bytes for
    apdu.sendBytesLong(sigBuff, (short) 0, (short) (sigLen + 2));
}



On Java Side:

Code: Select all

FileInputStream certis = new FileInputStream(cert);
X509Certificate c1 = new X509Certificate(certis);

...

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
byte[] testsig = new byte[64];
System.arraycopy(raw_signature,0, testsig, 0, 64);
Signature signature = Signature.getInstance("SHA1withRSA", "BC");
signature.initVerify(c1.getPublicKey());
System.out.println(c1.getPublicKey());
System.out.println(signature);
System.out.println(file_data.length+":> "+new String(file_data));
signature.update(file_data);
System.out.println("VERIFY > "+signature.verify(testsig)+" <");


The result is false.

Can someone give me any advice on how to make a signature with java card and verify it? Thanks in advance.
Onward...

User avatar
horse dream
Posts: 76
Joined: Thu May 21, 2015 11:48 pm
Points :138
Contact:

Re: how to make a signature with java card and verify it

Post by horse dream » Mon Nov 30, 2015 11:08 pm

Simply use Signature and ALG_RSA_SHA_PKCS1 instead of SignatureMessageRecovery and ALG_RSA_SHA_ISO9796_MR on the Java Card side.

If you want message recovery you may have to use the Bouncy Castle library at the Java side.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 25 guests

JavaCard OS : Disclaimer