-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBlob.java
More file actions
66 lines (49 loc) · 1.71 KB
/
Blob.java
File metadata and controls
66 lines (49 loc) · 1.71 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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.security.*;
/**
* Blob
*/
public class Blob {
String encryption;
public Blob(String filePath) throws Exception {
StringBuilder builder = new StringBuilder();
BufferedReader buffer = new BufferedReader(new FileReader(filePath));
while (buffer.ready()) {
builder.append((char) buffer.read());
}
buffer.close();
encryption = encryptThisString(builder.toString());
File file = new File("./objects/" + encryption);
file.createNewFile();
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("./objects/" + encryption)));
pw.print(builder.toString());
pw.close();
}
public static String encryptThisString(String input) {
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(input.getBytes());
byte[] b = md.digest();
char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
StringBuffer buf = new StringBuffer();
for (int j = 0; j < b.length; j++) {
buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
buf.append(hexDigit[b[j] & 0x0f]);
}
return buf.toString();
}
// For specifying wrong message digest algorithms
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
public String getEncryption() {
return encryption;
}
}