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.

Problem of DER bytes

JavaCard Applet Development Related Questions and Answers.
Heather
Posts: 24
Joined: Mon Nov 30, 2015 5:41 am
Points :121
Contact:

Problem of DER bytes

Post by Heather » Thu Nov 03, 2016 1:12 am

I am implementing Fips 196 and I am caught in a problem recently. I encode the user certificate into encoded byte array and wrap the DER byte array into string object and when I tried to get these DER encoded bytes back again. I got the different bytes. Why this happened? Any help here?

Code: Select all

                         certData = response.getData();     
                         for(int i=0; i<certData.length; i++)
                         {
                              System.out.print(certData);

                         }

               String d = new String (certData);

               byte[] testarr = d.getBytes();

                    for(int i=0; i<testarr.length; i++)

                    {

                         System.out.print(d.getBytes()[i]);

                    }

chico0609
Posts: 59
Joined: Mon Sep 14, 2015 5:05 am
Points :416
Contact:

Re: Problem of DER bytes

Post by chico0609 » Thu Nov 03, 2016 11:02 pm

Your problem is just because bytes are signed. Any byte in the 0x80-0xFF range will be signed extended to int and printed as a negative integer in range -127...-1.

Heather
Posts: 24
Joined: Mon Nov 30, 2015 5:41 am
Points :121
Contact:

Re: Problem of DER bytes

Post by Heather » Fri Nov 04, 2016 1:36 am

chico0609 wrote:Your problem is just because bytes are signed. Any byte in the 0x80-0xFF range will be signed extended to int and printed as a negative integer in range -127...-1.


Thanks for your help. If the problem is due to sign extension, how can I modify my code?

chico0609
Posts: 59
Joined: Mon Sep 14, 2015 5:05 am
Points :416
Contact:

Re: Problem of DER bytes

Post by chico0609 » Fri Nov 04, 2016 3:58 am

Clear the high order bits with a AND

Code: Select all

int unsigned_byte = certData[i] & 0xff;

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: Bing [Bot] and 58 guests

JavaCard OS : Disclaimer