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.

Generate random number

JavaCard Applet Development Related Questions and Answers.
Christy16
Posts: 12
Joined: Wed Dec 21, 2016 11:45 pm
Points :168
Contact:

Generate random number

Post by Christy16 » Sun Jul 23, 2017 11:51 pm

I am trying to generate random number for a get challenge command, but every time I always got the same number, I need a 8 byte unique number generated every time.Here is my code. Can anyone help me out? Thanks a lot.

Code: Select all

         byte[] apduBuffer = apdu.getBuffer();
         RandomData random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
         byte[] randomArray = new byte[8];
          random.setSeed(randomArray,(short)0,(short)8);
         random.generateData(randomArray,(short)0, (short)8);
         Util.arrayCopy(randomArray,(short)0,apduBuffer,(short)0,(short)8);
         apdu.setOutgoingAndSend((short)0, (short)8);

Crawford
Posts: 39
Joined: Thu Sep 17, 2015 11:50 pm
Points :246
Contact:

Re: Generate random number

Post by Crawford » Mon Jul 24, 2017 11:12 pm

If you remove the setSeeed call, you will get a different result from the random number generator, since you are seeding the generator with the same value.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 38 guests

JavaCard OS : Disclaimer