Java代码

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
package com;

import java.math.BigInteger;
import java.security.MessageDigest;

/**
* @author LeDao
* @company
* @create 2021-01-13 5:15
*/
public class Md5 {

public static final String KEY_MD5 = "MD5";

public static String getResult(String inputStr)
{
System.out.println("=======加密前的数据:"+inputStr);
BigInteger bigInteger=null;

try {
MessageDigest md = MessageDigest.getInstance(KEY_MD5);
byte[] inputData = inputStr.getBytes();
md.update(inputData);
bigInteger = new BigInteger(md.digest());
} catch (Exception e) {e.printStackTrace();}
System.out.println("MD5加密后:" + bigInteger.toString(16));
return bigInteger.toString(16);
}

public static void main(String[] args)
{
try {
String inputStr = "123456";
getResult(inputStr);
} catch (Exception e) {
e.printStackTrace();
}

}
}

结果

img