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.

Do ECC cryptography, ECDSA and elliptic Diffie-Hellman on a JavaCard

JavaCard Applet Development Related Questions and Answers.
leogen
Posts: 13
Joined: Wed Jan 06, 2016 2:45 am
Points :94
Contact:

Do ECC cryptography, ECDSA and elliptic Diffie-Hellman on a JavaCard

Post by leogen » Wed Jan 06, 2016 2:54 am

I have already bought some java cards and I m going to do ECC cryptography, ECDSA and elliptic Diffie-Hellman on a JavaCard. Could you share any code samples with me? I would be greatly grateful for any reply!

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

Re: Do ECC cryptography, ECDSA and elliptic Diffie-Hellman on a JavaCard

Post by btwtiger » Tue Jan 12, 2016 10:20 pm

leogen wrote:I have already bought some java cards and I m going to do ECC cryptography, ECDSA and elliptic Diffie-Hellman on a JavaCard. Could you share any code samples with me? I would be greatly grateful for any reply!


Hi guy!

I have written an applet for testing ECDH. Maybe this will be helpful to you!

Code: Select all

private byte[] SimulatedReceivedKeybuf;
private byte[] tempbuf;
private KeyPair KeyPairH;
private KeyAgreement SharedKey;
private ECPublicKey SimulatedReceivedKey;
protected void initialize(short KeySize)
     {
          if (SimulatedReceivedKeybuf != null || tempbuf != null)
                ISOException.throwIt((short)0x9B01);
         
          //Initialize two keypairs
          try{
               KeyPairH = new KeyPair(KeyPair.ALG_EC_FP,KeySize);
               KeyPairH.genKeyPair();
               SimulatedReceivedKey = (ECPublicKey)KeyPairH.getPublic();
               KeyPairH = new KeyPair(KeyPair.ALG_EC_FP,KeySize);
               KeyPairH.genKeyPair();
          }
          catch(Exception e){ISOException.throwIt((short)0x9A01);}
          //create a useful temporary buffer
          tempbuf = JCSystem.makeTransientByteArray((short)256,JCSystem.CLEAR_ON_RESET);
          //create the buffer for the shared key computation thanks to the SimulatedReceiveKey (param W)
          SimulatedReceivedKeybuf = JCSystem.makeTransientByteArray(((ECPublicKey)KeyPairH.getPublic()).getW(tempbuf, (short) 0),JCSystem.CLEAR_ON_RESET);
          SimulatedReceivedKey.getW(SimulatedReceivedKeybuf, (short)0);
          //Initialize the Key agreement object
          SharedKey = KeyAgreement.getInstance(KeyAgreement.ALG_EC_SVDP_DH, false);
          SharedKey.init(KeyPairH.getPrivate());
     }
     
private void GenerateSecretKey()
     {
          //Compute and set the shared secret key into the temporary buffer
          SharedKey.generateSecret(SimulatedReceivedKeybuf, (short)0, (short)SimulatedReceivedKeybuf.length, tempbuf, (short)0);
     }
Onward...

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 61 guests

JavaCard OS : Disclaimer