|
@@ -12,6 +12,7 @@ public class Message implements Serializable {
|
|
|
private boolean directMessage;
|
|
private boolean directMessage;
|
|
|
private String fromIp;
|
|
private String fromIp;
|
|
|
private long timestamp;
|
|
private long timestamp;
|
|
|
|
|
+ private String content;
|
|
|
private String contentForReceiver;
|
|
private String contentForReceiver;
|
|
|
private String contentForSender;
|
|
private String contentForSender;
|
|
|
private boolean encrypted = false;
|
|
private boolean encrypted = false;
|
|
@@ -32,17 +33,19 @@ public class Message implements Serializable {
|
|
|
if (!encrypted) {
|
|
if (!encrypted) {
|
|
|
this.contentForSender = CryptoUtils.encrypt(contentForSender, senderKey);
|
|
this.contentForSender = CryptoUtils.encrypt(contentForSender, senderKey);
|
|
|
this.contentForReceiver = CryptoUtils.encrypt(contentForReceiver, receiverKey);
|
|
this.contentForReceiver = CryptoUtils.encrypt(contentForReceiver, receiverKey);
|
|
|
|
|
+ content = "";
|
|
|
encrypted = true;
|
|
encrypted = true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void decrypt(PrivateKey privateKey, PublicKey publicKey) throws Exception {
|
|
public void decrypt(PrivateKey privateKey, PublicKey publicKey) throws Exception {
|
|
|
- if (!encrypted) {
|
|
|
|
|
|
|
+ if (encrypted) {
|
|
|
if (didISendThis(publicKey)) {
|
|
if (didISendThis(publicKey)) {
|
|
|
- this.contentForSender = CryptoUtils.decrypt(contentForSender, privateKey);
|
|
|
|
|
|
|
+ this.content = CryptoUtils.decrypt(contentForSender, privateKey);
|
|
|
} else {
|
|
} else {
|
|
|
- this.contentForReceiver =CryptoUtils.decrypt(contentForReceiver, privateKey);
|
|
|
|
|
|
|
+ this.content = CryptoUtils.decrypt(contentForReceiver, privateKey);
|
|
|
}
|
|
}
|
|
|
|
|
+ encrypted = false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -53,11 +56,8 @@ public class Message implements Serializable {
|
|
|
public PublicKey getSenderKey(){
|
|
public PublicKey getSenderKey(){
|
|
|
return senderKey;
|
|
return senderKey;
|
|
|
}
|
|
}
|
|
|
- public String getContentForReceiver(){
|
|
|
|
|
- return contentForReceiver;
|
|
|
|
|
- }
|
|
|
|
|
- public String getContentForSender(){
|
|
|
|
|
- return contentForSender;
|
|
|
|
|
|
|
+ public String getContent(){
|
|
|
|
|
+ return content;
|
|
|
}
|
|
}
|
|
|
public void setDirectMessage(String fromIp, int port){
|
|
public void setDirectMessage(String fromIp, int port){
|
|
|
directMessage = true;
|
|
directMessage = true;
|