@@ -41,20 +41,25 @@ public class AESCommunicator {
4141 private Cipher decryptaescipher ;
4242 private Deflater deflater ;
4343 private Inflater inflater ;
44-
44+ private boolean messageaudit = false ;
4545 /**
4646 * @param secretkey
4747 * @throws Exception
4848 */
4949 public AESCommunicator (SecretKey secretkey ) throws Exception {
50+ this (secretkey ,false );
51+
52+ }
53+
54+ public AESCommunicator (SecretKey secretkey ,boolean messageaudit ) throws Exception {
5055 this .secretkey = secretkey ;
5156 encryptaescipher = Cipher .getInstance ("AES" );
5257 encryptaescipher .init (Cipher .ENCRYPT_MODE , secretkey );
5358 decryptaescipher = Cipher .getInstance ("AES" );
5459 decryptaescipher .init (Cipher .DECRYPT_MODE , secretkey );
5560 deflater = new Deflater ();
5661 inflater = new Inflater ();
57-
62+ this . messageaudit = messageaudit ;
5863 }
5964
6065 /**
@@ -64,6 +69,11 @@ public AESCommunicator(SecretKey secretkey) throws Exception {
6469 */
6570 public byte [] zipandencrypt (String message ) throws Exception {
6671 try {
72+ if (this .messageaudit ) {
73+ logger .info ("--------------------------- FULL MESSAGE AUDIT (before encryption)-----------------------" );
74+ logger .info (message );
75+ logger .info ("--------------------------- FULL MESSAGE AUDIT END (after encryption) -------------------" );
76+ }
6777 if (message ==null ) return null ;
6878 byte [] messagebinary = message .getBytes ("UTF-8" );
6979 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
@@ -151,6 +161,7 @@ public static void main(String args[]) {
151161 */
152162 public static AESCommunicator performServerHandshake (MessageSimpleReader reader , MessageBufferedWriter writer )
153163 throws Exception {
164+
154165 reader .returnNextMessageStart ();
155166 reader .returnNextStartStructure ("RSAKEY" );
156167 byte [] rsapublickey = reader .returnNextLargeBinary ("PUBLICKEY" ).getContent ();
@@ -164,7 +175,7 @@ public static AESCommunicator performServerHandshake(MessageSimpleReader reader,
164175 byte [] aeskey = secretKey .getEncoded ();
165176
166177 // ----------- keep AES keys ----
167- AESCommunicator aescommunicator = new AESCommunicator (secretKey );
178+ AESCommunicator aescommunicator = new AESCommunicator (secretKey , writer . getMessageAudit () );
168179 // --- Encrypt AES key with RSA key ----
169180
170181 KeyFactory kf = KeyFactory .getInstance ("RSA" );
0 commit comments