publicstaticStringgetMD5(Stringstring){byte[]hash;try{hash=MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));}catch(NoSuchAlgorithmExceptione){thrownewRuntimeException("Huh, MD5 should be supported?",e);}catch(UnsupportedEncodingExceptione){thrownewRuntimeException("Huh, UTF-8 should be supported?",e);}StringBuilderhex=newStringBuilder(hash.length*2);for(byteb:hash){if((b&0xFF)<0x10)hex.append("0");hex.append(Integer.toHexString(b&0xFF));}returnhex.toString();}
importjava.security.MessageDigest;importjava.security.NoSuchAlgorithmException;publicstaticStringgetMD5(byte[]bytes){byte[]hash;try{hash=MessageDigest.getInstance("MD5").digest(bytes);}catch(NoSuchAlgorithmExceptione){thrownewRuntimeException("Huh, MD5 should be supported?",e);}StringBuilderhex=newStringBuilder(hash.length*2);for(byteb:hash){if((b&0xFF)<0x10)hex.append("0");hex.append(Integer.toHexString(b&0xFF));}returnhex.toString();}