-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageLogger.java
More file actions
25 lines (22 loc) · 1.08 KB
/
MessageLogger.java
File metadata and controls
25 lines (22 loc) · 1.08 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
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
public class MessageLogger {
private static final String LOG_FILE = "encrypted_messages.txt";
private static boolean logStarted = false;
public static synchronized void logMessage(String from, String to, String encrypted, String signature) {
try (FileWriter writer = new FileWriter(LOG_FILE, true)) {
if (!logStarted && !new java.io.File(LOG_FILE).exists()) {
writer.write("=== Encrypted Message Log - Started at " + LocalDateTime.now() + " ===\n");
logStarted = true;
}
writer.write("[" + LocalDateTime.now() + "] FROM: " + from + " TO: " + to + "\n");
writer.write("ENCRYPTION: AES-ENCRYPTED\n");
writer.write("ENCRYPTED: " + encrypted + "\n");
writer.write("SIGNATURE: " + signature + "\n");
writer.write("----------------------------------------\n");
} catch (IOException e) {
System.err.println("Failed to write to log: " + e.getMessage());
}
}
}