FULL PRODUCT VERSION :
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
SunOS 5.8 Generic_108528-20 sun4u sparc SUNW,Ultra-250
A DESCRIPTION OF THE PROBLEM :
Taking a byte array from a MessageDigest and then converting it to a String does not produce the correct character conversion. All negative integer byte values are converted to a '?'.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The problem only seems to exist on the Solaris machine. Running this on Windows provides the correct results. Executing the code below will provide the reproduction of the problem.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Digest:
ACTUAL -
Digest: i???????>????d
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.*;
import java.nio.*;
import java.security.*;
import java.io.UnsupportedEncodingException;
public class WorkSheet
{
public static void main(String args[])
{
String s = "some string to input";
String s1 = "more string";
try {
MessageDigest messagedigest = MessageDigest.getInstance("SHA");
messagedigest.update(s.getBytes());
messagedigest.update(s1.getBytes());
byte[] b = messagedigest.digest();
try
str = new String(b, "ISO-8859-1");
} catch(UnsupportedEncodingException uee) { }
System.out.println("Digest: " + str);
} catch(NoSuchAlgorithmException _ex) {
System.err.println("NoSuchAlgorithmException");
}
}
---------- END SOURCE ----------
###@###.### 2005-2-10 02:09:10 GMT
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
SunOS 5.8 Generic_108528-20 sun4u sparc SUNW,Ultra-250
A DESCRIPTION OF THE PROBLEM :
Taking a byte array from a MessageDigest and then converting it to a String does not produce the correct character conversion. All negative integer byte values are converted to a '?'.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The problem only seems to exist on the Solaris machine. Running this on Windows provides the correct results. Executing the code below will provide the reproduction of the problem.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Digest:
ACTUAL -
Digest: i???????>????d
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.*;
import java.nio.*;
import java.security.*;
import java.io.UnsupportedEncodingException;
public class WorkSheet
{
public static void main(String args[])
{
String s = "some string to input";
String s1 = "more string";
try {
MessageDigest messagedigest = MessageDigest.getInstance("SHA");
messagedigest.update(s.getBytes());
messagedigest.update(s1.getBytes());
byte[] b = messagedigest.digest();
try
str = new String(b, "ISO-8859-1");
} catch(UnsupportedEncodingException uee) { }
System.out.println("Digest: " + str);
} catch(NoSuchAlgorithmException _ex) {
System.err.println("NoSuchAlgorithmException");
}
}
---------- END SOURCE ----------
###@###.### 2005-2-10 02:09:10 GMT
- duplicates
-
JDK-6219899 when you convert a byte[] to a String and back with negative numbers it fails
-
- Closed
-