-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMd5.java
executable file
·47 lines (41 loc) · 1.18 KB
/
Md5.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
41
42
43
44
45
46
47
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Md5 {
public static void main(String[] args){
String value="hello";
String value2="hello";
// печать HashCode для выражения
printArray(getMD5Hash(value.getBytes()));
// печать HashCode для выражения
printArray(getMD5Hash(value2.getBytes()));
}
protected static byte[] getMD5Hash(byte[] value){
MessageDigest m;
byte[] returnValue=null;
try {
m = MessageDigest.getInstance("MD5");
//m.reset();
m.update(value,0,value.length);
returnValue=m.digest();
//returnValue = new BigInteger(1,m.digest()).toByteArray();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return returnValue;
}
public static void printArray(byte[] array){
for(int counter=0;counter<array.length;counter++){
if(counter==0){
System.out.print(" ");
}else{
System.out.print(", ");
}
if(array[counter]<0){
System.out.print(array[counter]+256);
}else{
System.out.print(array[counter]);
}
}
System.out.println();
}
}