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
|
public
class
Demo {
/**
* @param args
* @throws NoSuchAlgorithmException
*/
public
static
void
main(String[] args)
throws
NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance(
"md5"
);
String password =
"123456"
;
byte
[] bytes = digest.digest(password.getBytes());
StringBuffer buffer =
new
StringBuffer();
for
(
byte
b: bytes){
int
number = b &
0xff
;
//加盐
String hex = Integer.toHexString(number);
if
(hex.length()==
1
){
buffer.append(
"0"
);
}
buffer.append(hex);
}
//md5加密后的值
System.out.println(buffer);
}
}
|