Java tutorial
//package com.java2s; //License from project: Open Source License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { static public String md5(String str) { MessageDigest algorithm = null; try { algorithm = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } if (algorithm != null) { algorithm.reset(); algorithm.update(str.getBytes()); byte[] bytes = algorithm.digest(); StringBuilder hexString = new StringBuilder(); for (byte b : bytes) { if (Integer.toHexString(0xFF & b).length() == 1) hexString.append("0").append(Integer.toHexString(0xFF & b)); else hexString.append(Integer.toHexString(0xFF & b)); } return hexString.toString(); } return ""; } }