I want to compute md5 hash from a MimeMessage type.I use the following code to do this:

      private static String convertToHex(byte[] data) {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < data.length; i++) {
            int halfbyte = (data[i] >>> 4) & 0x0F;
            int two_halfs = 0;
            do {
                if ((0 <= halfbyte) && (halfbyte <= 9))
                    buf.append((char) ('0' + halfbyte));
                    buf.append((char) ('a' + (halfbyte - 10)));
                halfbyte = data[i] & 0x0F;
            } while(two_halfs++ < 1);
        return buf.toString();

       private static  String MD5(String text)    {
        MessageDigest md;
        md = MessageDigest.getInstance("MD5");
        byte[] md5hash = new byte[32];
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        md5hash = md.digest();
        return convertToHex(md5hash);

The code works perfectly!The problem is with the MimeMessage!I have to turn the MimeMessage into a String and then use md5 code!When the MimeMessage is Multipart ,every time i close the programm the next gives me a different md5 hash!!!The code i use to turn tha MimeMessage into a String is the following :

//This iis an example code
MimeMessage message;
String temp;

//i use it like this message.getInputStream() and then i turn InputStream to a String

 //Input stream to a string
    public static String parseISToString(java.io.InputStream is){
        java.io.DataInputStream din = new java.io.DataInputStream(is);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while((line=din.readLine()) != null){
        }catch(Exception ex){
        }catch(Exception ex){}
        return sb.toString();

If MimeMessage is not Multipart it works just fine!!Has anybody an idea why this happenning to Multipart MimeMessage??

I found the problem!This is how you turn a MimeMessage to a String :

int size;
           InputStream temp1 = null;
           String temp = new String();
            byte[] b;
           String value;

            b=new byte[size];
            value=new String(b);

The value is the String you put in MD5(value) !!!!