001 package com.khubla.pragmatach.framework.crypto; 002 003 import java.math.BigInteger; 004 import java.security.MessageDigest; 005 006 import com.khubla.pragmatach.framework.api.PragmatachException; 007 008 /** 009 * @author tome 010 */ 011 public class HashUtil { 012 public static String MD5(String str) throws PragmatachException { 013 try { 014 final MessageDigest messageDigest = MessageDigest 015 .getInstance("MD5"); 016 messageDigest.reset(); 017 messageDigest.update(str.getBytes("UTF-8")); 018 final byte[] digest = messageDigest.digest(); 019 final BigInteger bigInt = new BigInteger(1, digest); 020 String hashtext = bigInt.toString(16); 021 while (hashtext.length() < 32) { 022 hashtext = "0" + hashtext; 023 } 024 return hashtext; 025 } catch (final Exception e) { 026 throw new PragmatachException("Exception in MD5", e); 027 } 028 } 029 }