1package com.soft.reg.common;
2
3import java.security.MessageDigest;
4
5public class Testmd5 {
6
7 public final static String MD5(String s) {
8 char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
9 'a', 'b', 'c', 'd', 'e', 'f' };
10 try {
11 byte[] strTemp = s.getBytes();
12 MessageDigest mdTemp = MessageDigest.getInstance("MD5");
13 mdTemp.update(strTemp);
14 byte[] md = mdTemp.digest();
15 int j = md.length;
16 char str[] = new char[j * 2];
17 int k = 0;
18 for (int i = 0; i < j; i++) {
19 byte byte0 = md[i];
20 str[k++] = hexDigits[byte0 >>> 4 & 0xf];
21 str[k++] = hexDigits[byte0 & 0xf];
22 }
23 return new String(str);
24 } catch (Exception e) {
25 return null;
26 }
27 }
28
29 public static void main(String[] args) {
30 System.out.print(Testmd5.MD5("abc"));
31 }
32
33}
34
posted on 2007-09-18 12:17
天问 阅读(308)
评论(0) 编辑 收藏