Java tutorial
//package com.java2s; import java.security.MessageDigest; public class Main { private static MessageDigest mDigest = null; public static String toMD5(String key) { String cacheKey; if (mDigest == null) { return String.valueOf(key.hashCode()); } mDigest.update(key.getBytes()); cacheKey = bytesToHexString(mDigest.digest()); return cacheKey; } private static String bytesToHexString(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(0xFF & bytes[i]); if (hex.length() == 1) { sb.append('0'); } sb.append(hex); } return sb.toString(); } }