19
Sep
This utility class can generate md5 of any string and is also compatible with PHP.
import java.security.MessageDigest; /** * @author Sudhaker Raj (http://sudhaker.com) */ public class Md5Util { /** * @param value * @return */ public static String encodeMd5(String value) { StringBuffer encoded = new StringBuffer(); if (value != null) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(value.getBytes()); byte[] digest = md5.digest(); for (int i = 0; i < digest.length; ++i) { int b = (int) digest[i] & 0xFF; if (b < 16) encoded.append("0"); encoded.append(Integer.toHexString(b)); } } catch (Exception e) { // ignore exceptions } } return encoded.toString(); } }
1
September 19th, 2008 at 5:24 pm
In case you need stronger hash,