-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathReceiver.java
35 lines (29 loc) · 1.15 KB
/
Receiver.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
public class Receiver {
static String deviceName = "dev2";
static String sharedKey = "LGWlhb329Y09oluI";
static String imagePathToStore = "received.jpg";
public static void main(String args[]) {
Client client = new Client();
Image_Utils imageUtils = new Image_Utils();
AES_Utils aesUtils;
// Register device
System.out.println("Registering...");
String msg = "SHARE #pubkey key @senz #time "+client.getTimeStamp()+" ^"+deviceName+" signature";
client.sendMessage(msg);
// Receive message
System.out.println("Ready to receive image");
String reply = client.receiveMessage();
String byteString = reply.split(" ")[2];
System.out.println("Image received...");
// Decode using aes crypto
aesUtils = new AES_Utils(sharedKey);
byteString = aesUtils.decrypt(byteString);
// Save Image
imageUtils.stringToImage(byteString, imagePathToStore);
System.out.printf("Image saved (%s)\n", imagePathToStore);
// Unregister device
System.out.println("Unregistering...");
msg = "UNSHARE #pubkey key @senz #time "+client.getTimeStamp()+" ^"+deviceName+" signature";
client.sendMessage(msg);
}
}