Ignore:
Timestamp:
05/31/19 11:39:55 (5 years ago)
Author:
bln4
Message:

Can now encrypt specific items on an encrypted frame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/encryption/io/EncryptedExpWriter.java

    r1399 r1400  
    2222import org.expeditee.gui.MessageBay;
    2323import org.expeditee.io.ExpWriter;
     24import org.expeditee.items.Item;
    2425import org.expeditee.items.Text;
    2526import org.expeditee.settings.UserSettings;
     
    6061       
    6162        @Override
     63        public void outputFrame(Frame frame) throws IOException {
     64                individualItemEncryption(frame);
     65                super.outputFrame(frame);
     66        }
     67       
     68        @Override
    6269        protected void writeLine(String line) throws IOException {
    6370                // do not write empty lines
     
    7178                _writer.write(toWrite);
    7279                _stringWriter.append(toWrite);
     80        }
     81       
     82        private void individualItemEncryption(Frame frame) {
     83                // Find items with their own encryption label.
     84                Collection<Item> itemsWithEncryptionLabel = frame.getAllItems();
     85                itemsWithEncryptionLabel.removeIf(i -> i.getEncryptionLabel() == null || i.getEncryptionLabel().isEmpty());
     86               
     87                for (Item i: itemsWithEncryptionLabel) {
     88                        // Encrypt the Text Items
     89                        if (i instanceof Text) {
     90                                byte[] keyBytes = resolveKeyFromLabel(i.getEncryptionLabel(), "(actually item) on " + i.getParent().getName());
     91                                if (keyBytes == null) { continue; }
     92                                SecretKeySpec key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
     93                                byte[] encryptedBytes = EncryptSymmetric(i.getText().getBytes(), key);
     94                                i.setText(Base64.getEncoder().encodeToString(encryptedBytes));
     95                        }
     96                }
    7397        }
    7498       
Note: See TracChangeset for help on using the changeset viewer.