01: package liquibase.util;
02:
03: import java.security.MessageDigest;
04:
05: /**
06: * Generates md5-sums based on a string.
07: */
08: public class MD5Util {
09: public static String computeMD5(String input) {
10: MessageDigest digest;
11: try {
12: digest = MessageDigest.getInstance("MD5");
13: digest.update(input.getBytes("UTF-8"));
14: } catch (Exception e) {
15: throw new RuntimeException(e);
16: }
17: byte[] digestBytes = digest.digest();
18:
19: StringBuffer hexString = new StringBuffer();
20: for (byte digestByte : digestBytes) {
21: hexString.append(Integer.toHexString(0xFF & digestByte));
22: }
23: return hexString.toString();
24:
25: }
26: }
|