-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenSig.java
More file actions
66 lines (55 loc) · 2.25 KB
/
GenSig.java
File metadata and controls
66 lines (55 loc) · 2.25 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
package AuctioningSystem;
import java.io.*;
import java.security.*;
class GenSig {
public static void main(String[] args) {
/* Generate a DSA signature */
try {
// the rest of the code goes here
//Generate Keys
FileOutputStream fop;
ObjectOutputStream oos, privatekeyoos;
File file;
File keyfile = new File("publickeys.key");
User currentuser;
PrivateKey priv;
PublicKey pub;
PublicKey serverpub;
String[] names = {"Jack", "George", "Amy", "Nicole", "James"};
String[] emails = {"jack@gmail.com", "george@hotmail.com", "amy@amy.com", "nicole@gmail.com", "james@james.com"};
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
keyGen.initialize(1024, random);
KeyPair pair = keyGen.generateKeyPair();
serverpub = pair.getPublic();
priv = pair.getPrivate();
file = new File("serverprivate.key");
fop = new FileOutputStream(file);
oos = new ObjectOutputStream(fop);
oos.writeObject(priv);
fop.close();
oos.close();
for(int i = 1; i <= 5; i++){
pair = keyGen.generateKeyPair();
priv = pair.getPrivate();
pub = pair.getPublic();
currentuser = new User(priv,serverpub, names[i-1], emails[i-1], i);
//Add client public key to publickey file
file = new File("public" + i + ".key");
fop = new FileOutputStream(file);
oos = new ObjectOutputStream(fop);
oos.writeObject(pub);
oos.close();
//Add private keys into separate files id.key
file = new File("user" + i + ".ser");
fop = new FileOutputStream(file);
oos = new ObjectOutputStream(fop);
oos.writeObject(currentuser);
fop.close();
oos.close();
}
} catch (Exception e) {
System.err.println("Caught exception " + e.toString());
}
}
}