Hello to all!I m new to forum so excuse me for any mistakes!!Iwan't to get MD5 hash from MimeMessage type!I use the following code to take MD5 :
//MD5 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)); else 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);
As you understand i have to convert MimeMessage into String!My problem is when MimeMessage is type Multipart every time I close my programm the next time it gives me a different MD5 hash!!!But when MimeMessage is NOT Multipart it gives me always the same MD5 hash.The code i use to convert MimeMessage to String is the following:
//This iis an example code MimeMessage message; String temp; //i use it like this temp=parseISToString(message.getInputStream()); //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(); try{ String line = null; while((line=din.readLine()) != null){ sb.append(line).append("\n"); } }catch(Exception ex){ ex.getMessage(); }finally{ try{ is.close(); }catch(Exception ex){} } return sb.toString(); }
I would be grateful if someone gave a solution to this or give me a new way to compute MD5 hash from a MimeMessage type!!Thank you...