Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert byteArray to String with J2ME

843811Jun 9 2005 — edited Apr 8 2008
I want to convert the bit array of the message digest to String and send it in SMS. I'm using bouncy castle to do the SHA256, however error occurs when I try to run this method. How can I correct this or if it is not possible are there any other method to send the byte array via SMS?

public String runSHA256(String message){

SHA256Digest digEng = new SHA256Digest();
byte [] mesgBytes = message.getBytes();
digEng.update( mesgBytes, 0, mesgBytes.length );
byte [] digest = new byte[digEng.getDigestSize()];
digEng.doFinal(digest, 0);

String sd = new String(digest);
return sd;
}

I tried the following code in J2SE, it byte array convert back to string correctly but in J2ME the same error happens

String s1="Hello";

String s3="";
try{
byte [] byteArray = s1.getBytes("UTF8");
String s2= new String(byteArray ,"UTF8");
s3=s2;
}catch(IOException e1) {}
System.out.println("String: " + s3);

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 6 2008
Added on Jun 9 2005
2 comments
513 views