@@ -155,11 +155,9 @@ public void finish() throws ASAPSecurityException {
155155 }
156156 }
157157
158+ // must be after signing
158159 if (this .cipher != null ) {
159160 try {
160- // encrypted asap message
161- byte [] asapMessageAsBytes = this .asapMessageOS .toByteArray ();
162-
163161 // get symmetric key
164162 SecretKey encryptionKey = this .keyStorage .generateSymmetricKey ();
165163 byte [] encodedSymmetricKey = encryptionKey .getEncoded ();
@@ -170,21 +168,28 @@ public void finish() throws ASAPSecurityException {
170168 // send encrypted key
171169 this .writeByteArray (encryptedSymmetricKeyBytes , this .realOS );
172170
171+ // get maybe signed asap message
172+ byte [] asapMessageAsBytes = this .asapMessageOS .toByteArray ();
173+
173174 // encrypt message with symmetric key
174175 try {
175- this . cipher = Cipher .getInstance (keyStorage .getSymmetricEncryptionAlgorithm ());
176- this . cipher .init (Cipher .ENCRYPT_MODE , encryptionKey );
176+ Cipher symmetricCipher = Cipher .getInstance (keyStorage .getSymmetricEncryptionAlgorithm ());
177+ symmetricCipher .init (Cipher .ENCRYPT_MODE , encryptionKey );
177178
179+ /*
178180 // block by block
179181 int i = 0;
180182 while(i + MAX_ENCRYPTION_BLOCK_SIZE < asapMessageAsBytes.length) {
181- this . cipher .update (asapMessageAsBytes , i , MAX_ENCRYPTION_BLOCK_SIZE );
183+ symmetricCipher .update(asapMessageAsBytes, i, MAX_ENCRYPTION_BLOCK_SIZE);
182184 i += MAX_ENCRYPTION_BLOCK_SIZE;
183185 }
184186
185187 int lastStepLen = asapMessageAsBytes.length - i;
186- byte [] encryptedContent = this .cipher .doFinal (asapMessageAsBytes , i , lastStepLen );
188+ symmetricCipher.update(asapMessageAsBytes, i, lastStepLen);
189+ byte[] encryptedContent = symmetricCipher.doFinal();
190+ */
187191
192+ byte [] encryptedContent = symmetricCipher .doFinal (asapMessageAsBytes );
188193 this .writeByteArray (encryptedContent , this .realOS );
189194 } catch (NoSuchAlgorithmException | InvalidKeyException | NoSuchPaddingException e ) {
190195 throw new ASAPSecurityException (this .getLogStart (), e );
0 commit comments