-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathSender.java
39 lines (31 loc) · 1.24 KB
/
Sender.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
import java.util.Scanner;
public class Sender {
static String deviceName = "dev1";
static String sharedKey = "LGWlhb329Y09oluI";
static String imagePathToSend = "sample.jpg";
public static void main(String args[]) {
Client client = new Client();
Image_Utils imageUtils = new Image_Utils();
AES_Utils aesUtils;
Scanner sc = new Scanner(System.in);
// Register device
System.out.println("Registering device...");
String msg = "SHARE #pubkey key @senz #time "+client.getTimeStamp()+" ^"+deviceName+" signature";
client.sendMessage(msg);
// Convert image to byte string
String byteString = imageUtils.imageToString(imagePathToSend);
// Encrypt using AES Crypto
aesUtils = new AES_Utils(sharedKey);
byteString = aesUtils.encrypt(byteString);
// Send the message
System.out.println("Press enter to send the image...");
sc.nextLine();
msg = "DATA $image " + byteString +" @dev2 #time " + client.getTimeStamp() + " ^dev1 signature";
client.sendMessage(msg);
// Unregister device
System.out.println("Unregistering device...");
msg = "UNSHARE #pubkey key @senz #time " + client.getTimeStamp() +" ^"+ deviceName +" signature";
client.sendMessage(msg);
sc.close();
}
}