68
|
1 package fschmidt.util.java;
|
|
2
|
|
3 import java.io.UnsupportedEncodingException;
|
|
4 import java.security.MessageDigest;
|
|
5 import java.security.NoSuchAlgorithmException;
|
|
6
|
|
7 public class MD5Util {
|
|
8 public static String hex(byte[] array) {
|
|
9 StringBuffer sb = new StringBuffer();
|
|
10 for (byte anArray : array) {
|
|
11 sb.append(Integer.toHexString((anArray
|
|
12 & 0xFF) | 0x100).substring(1, 3));
|
|
13 }
|
|
14 return sb.toString();
|
|
15 }
|
|
16
|
|
17 public static String md5Hex(String message) {
|
|
18 try {
|
|
19 MessageDigest md =
|
|
20 MessageDigest.getInstance("MD5");
|
|
21 return hex(md.digest(message.getBytes("CP1252")));
|
|
22 } catch (NoSuchAlgorithmException e) {
|
|
23 } catch (UnsupportedEncodingException e) {
|
|
24 }
|
|
25 return null;
|
|
26 }
|
|
27 } |