JavaCard Applet Development Related Questions and Answers.
-
Heather
- Posts: 24
- Joined: Mon Nov 30, 2015 5:41 am
- Points :121
-
Contact:
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:
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:
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:
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;
Users browsing this forum: No registered users and 10 guests
JavaCard OS : Disclaimer
Board Disclaimer
The views and comments posted in these fora are personal and do not necessarily represent the those of the Management of JavaCard OS.
The Management of JavaCard OS does not, under any circumstances whatsoever, accept any responsibility for any advice, or recommentations, made by, or implied by, any member or guest vistor of JavaCard OS that results in any loss whatsoever in any manner to a member of JavaCard OS, or to any other person.
Furthermore, the Management of JavaCard OS is not, and cannot be, responsible for the content of any other Internet site(s) that have been linked to from JavaCard OS.