Java tutorial
//package com.java2s; import java.io.UnsupportedEncodingException; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static String getMD5EncryptedString(byte[] _encTarget) { String encTarget = ""; try { encTarget = new String(_encTarget, "UTF-8"); } catch (UnsupportedEncodingException e1) { System.out.println("error converting byte[] to string"); } MessageDigest mdEnc = null; try { mdEnc = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { System.out.println("Exception while encrypting to md5"); } // Encryption algorithm mdEnc.update(encTarget.getBytes(), 0, encTarget.length()); String md5 = new BigInteger(1, mdEnc.digest()).toString(16); while (md5.length() < 32) { md5 = "0" + md5; } return md5; } public static String getMD5EncryptedString(String encTarget) { MessageDigest mdEnc = null; try { mdEnc = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { System.out.println("Exception while encrypting to md5"); e.printStackTrace(); } // Encryption algorithm mdEnc.update(encTarget.getBytes(), 0, encTarget.length()); String md5 = new BigInteger(1, mdEnc.digest()).toString(16); while (md5.length() < 32) { md5 = "0" + md5; } return md5; } }