Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get MD5 String from Message Digest

I understand how it works but if I want to print out the MD5 as String how would I do that?

public static void getMD5(String fileName) throws Exception{     InputStream input =  new FileInputStream(fileName);     byte[] buffer = new byte[1024];      MessageDigest hash = MessageDigest.getInstance("MD5");     int read;     do {         read = input.read(buffer);         if (read > 0) {             hash.update(buffer, 0, read);         }     } while (read != -1);     input.close(); } 
like image 996
Tom Avatar asked Mar 29 '11 09:03

Tom


1 Answers

You can get it writing less:

String hex = (new HexBinaryAdapter()).marshal(md5.digest(YOUR_STRING.getBytes())) 
like image 104
arutaku Avatar answered Sep 28 '22 20:09

arutaku