Md5Utils

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cn.itcast.crm.utils;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import sun.misc.BASE64Encoder;
public class {
try {
MessageDigest md5 = MessageDigest.getInstance("md5");
byte []afterStr = md5.digest(oldStr.getBytes());
BASE64Encoder b64 = new BASE64Encoder();
return b64.encode(afterStr);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}*/
public static String encode(String oldStr){
try {
MessageDigest md5 = MessageDigest.getInstance("md5");
byte []afterStr = md5.digest(oldStr.getBytes());
BigInteger bigInt = new BigInteger(1, afterStr);
return bigInt.toString(16);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
System.out.println(encode("itcast123"));
// 21232f297a57a5a743894a0e4a801fc3
// 21232f297a57a5a743894a0e4a801fc3
}
}