Java tutorial
//package com.java2s; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; public class Main { private static MessageDigest mDigest; /** * Returns a 32 chararacter hexadecimal representation of an MD5 hash of the * given String. * * @param s the String to hash * @return the md5 hash */ public final static String md5(final String s) { try { final byte[] mBytes = mDigest.digest(s.getBytes("UTF-8")); final StringBuilder mBuilder = new StringBuilder(32); for (final byte aByte : mBytes) { final String mHex = Integer.toHexString(aByte & 0xFF); if (mHex.length() == 1) { mBuilder.append('0'); } mBuilder.append(mHex); } return mBuilder.toString(); } catch (final UnsupportedEncodingException ignored) { } return null; } }