Skip to content

Instantly share code, notes, and snippets.

@Metapyziks
Created January 28, 2013 00:32
Show Gist options
  • Select an option

  • Save Metapyziks/4651711 to your computer and use it in GitHub Desktop.

Select an option

Save Metapyziks/4651711 to your computer and use it in GitHub Desktop.
import java.security.*;
public class HashTest
{
public static void main(String[] args)
throws Exception
{
System.out.println(hash("testing"));
}
public static String hash(String message)
throws Exception
{
MessageDigest m = MessageDigest.getInstance("MD5");
byte[] digest = m.digest(message.getBytes("UTF-8"));
StringBuffer builder = new StringBuffer();
for(int i = 0; i < digest.length; ++i) {
builder.append(Integer.toHexString((digest[i] & 0xFF) | 0x100).substring(1, 3));
}
return builder.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment