Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Greg Miller http://www.principiaprogramatica.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Get MD5 hash in a few lines of Java

// MD5 in Java, short and sweet version.

   1  
   2      1 import java.security.*;
   3      2 import java.math.*;
   4      3 
   5      4 public class MD5 {
   6      5    public static void main(String args[]) throws Exception{
   7      6       String s="This is a test";
   8      7       MessageDigest m=MessageDigest.getInstance("MD5");
   9      8       m.update(s.getBytes(),0,s.length());
  10      9       System.out.println("MD5: "+new BigInteger(1,m.digest()).toString(16));
  11     10    }
  12     11 }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS