forked from MasterFlomaster1/JFXCrypto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrentHash.java
More file actions
93 lines (82 loc) · 2.62 KB
/
Copy pathCurrentHash.java
File metadata and controls
93 lines (82 loc) · 2.62 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package Hash;
import java.io.File;
public class CurrentHash {
public static final int MD2 = 0;
public static final int MD5 = 1;
public static final int SHA1 = 2;
public static final int SHA224 = 3;
public static final int SHA256 = 4;
public static final int SHA384 = 5;
public static final int SHA512 = 6;
private static MD2 md2 = new MD2();
private static MD5 md5 = new MD5();
private static SHA1 sha1 = new SHA1();
private static SHA224 sha224 = new SHA224();
private static SHA256 sha256 = new SHA256();
private static SHA384 sha384 = new SHA384();
private static SHA512 sha512 = new SHA512();
private static int currentHash;
public static void setCurrentHash(int a) {
currentHash = a;
}
private static int getCurrentHash() {
return currentHash;
}
public static String getCurrentHashName() {
switch (getCurrentHash()) {
case MD2:
return "MD2";
case MD5:
return "MD5";
case SHA1:
return "SHA-1";
case SHA224:
return "SHA-224";
case SHA256:
return "SHA-256";
case SHA384:
return "SHA-384";
case SHA512:
return "SHA-512";
}
return null;
}
public static String hashText(String input) {
switch (getCurrentHash()) {
case MD2:
return md2.getHashFromText(input);
case MD5:
return md5.getHashFromText(input);
case SHA1:
return sha1.getHashFromText(input);
case SHA224:
return sha224.getHashFromText(input);
case SHA256:
return sha256.getHashFromText(input);
case SHA384:
return sha384.getHashFromText(input);
case SHA512:
return sha512.getHashFromText(input);
}
return null;
}
public static String fileHashSum(File file) {
switch (getCurrentHash()) {
case MD2:
return md2.getHashFromFile(file);
case MD5:
return md5.getHashFromFile(file);
case SHA1:
return sha1.getHashFromFile(file);
case SHA224:
return sha224.getHashFromFile(file);
case SHA256:
return sha256.getHashFromFile(file);
case SHA384:
return sha384.getHashFromFile(file);
case SHA512:
return sha512.getHashFromFile(file);
}
return null;
}
}