-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConf.java
48 lines (40 loc) · 1.53 KB
/
Conf.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
48
package crypto;
import java.io.*;
import java.util.Properties;
public class Conf {
boolean mode;
String password;
String alias;
String peerAlias;
String keyStorePath;
String signature;
Properties prop;
public Conf() {
}
public void store(String path, String signature) throws FileNotFoundException, IOException {
String alias = this.prop.getProperty("alias");
String peerAlias = this.prop.getProperty("peerAlias");
OutputStream output = new FileOutputStream(path);
this.prop.setProperty("signature", signature);
this.prop.setProperty("mode", "decrypt");
this.prop.setProperty("keystore", peerAlias + ".keystore");
this.prop.setProperty("alias", peerAlias);
this.prop.setProperty("peerAlias", alias);
this.prop.store(output, null);
}
public void load(String path) throws FileNotFoundException, IOException {
InputStream input = new FileInputStream(path);
this.prop = new Properties();
this.prop.load(input);
this.mode = this.prop.getProperty("mode").equals("encrypt");
this.password = this.prop.getProperty("password");
this.alias = prop.getProperty("alias");
this.peerAlias = this.prop.getProperty("peerAlias");
this.keyStorePath = this.prop.getProperty("keystore");
String signature = this.prop.getProperty("signature");
// Signature is required only for decrypt mode.
if (signature != null) {
this.signature = signature;
}
}
}