-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleClient.java
84 lines (72 loc) · 2.35 KB
/
SimpleClient.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
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
/*
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
////////// Abigail H. Shriver //////////
////////// CSci 4243 Senior Design Project //////////
////////// Self-Tracking E-currency //////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
*/
import java.net.*;
import javax.net.ssl.*;
import java.io.*;
import java.util.*;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.*;
import sun.misc.*;
import javax.crypto.spec.SecretKeySpec;
public class SimpleClient{
static String algor = "AES";
static byte[] keyVal =
new byte[] {
0x00, 0x01, 0x02, 0x03,
0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x10, 0x11,
0x12, 0x13, 0x14, 0x15
};
static int port = 8080;
static String hostAddress = "localhost";
public static void main(String args[]) {
try{
//////// Still debugginf SSL socket
/*SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
Socket soc = ssf.createSocket("localhost",port);
/*SSLSocket sslSoc = (SSLSocket)sslsocketfactory.createSocket(
soc,
soc.getInetAddress().getHostAddress(),
soc.getPort(),
true
);*/
//ServerSocket serverSoc = ssf.createServerSocket(port);
////////
Socket soc = new Socket(hostAddress,port);
OutputStream outStream = soc.getOutputStream();
ObjectOutputStream objOutStream = new ObjectOutputStream(outStream);
Currency testCurrency1 = new Currency(
"sender2",
"testReciever1",
new ArrayList<String> (),
100.00,
0.00,
new ArrayList<String> (Arrays.asList(
"Restrictive Tree",
"entertainment",
"newspaperMagazines"
)),
"currency1"
);
SecretKeySpec key = new SecretKeySpec(keyVal, "AES");
Cipher c = Cipher.getInstance(algor);
c.init(Cipher.ENCRYPT_MODE, key);
SealedObject sealedCurrency = new SealedObject(testCurrency1, c);
objOutStream.writeObject(sealedCurrency);
objOutStream.writeObject(new String("another object from the client"));
objOutStream.close();
outStream.close();
soc.close();
}catch(Exception e){
System.out.println(e);
}
}
}