Changeset 1400
- Timestamp:
- 05/31/19 11:39:55 (5 years ago)
- Location:
- trunk/src/org/expeditee/encryption/io
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/encryption/io/EncryptedExpReader.java
r1399 r1400 12 12 import java.util.Arrays; 13 13 import java.util.Base64; 14 import java.util.Collection; 14 15 15 16 import javax.crypto.BadPaddingException; … … 23 24 import org.expeditee.gui.Frame; 24 25 import org.expeditee.io.ExpReader; 26 import org.expeditee.items.Item; 25 27 import org.expeditee.items.Text; 26 28 import org.expeditee.settings.identity.secrets.KeyList; … … 72 74 public Frame readFrame(final BufferedReader reader) throws IOException { 73 75 if (accessDenied) { return null; } 74 else return super.readFrame(reader); 76 else { 77 Frame unencryptedFrame = super.readFrame(reader); 78 individualItemDecryption(unencryptedFrame); 79 return unencryptedFrame; 80 } 81 } 82 83 private void individualItemDecryption(Frame frame) { 84 // Find items with their own encryption label. 85 Collection<Item> itemsWithEncryptionLabel = frame.getAllItems(); 86 itemsWithEncryptionLabel.removeIf(i -> i.getEncryptionLabel() == null || i.getEncryptionLabel().isEmpty()); 87 88 for (Item i: itemsWithEncryptionLabel) { 89 // Decrypt the Text Items 90 if (i instanceof Text) { 91 byte[] keyBytes = EncryptedExpWriter.resolveKeyFromLabel(i.getEncryptionLabel(), ""); 92 if (keyBytes == null) { continue; } 93 SecretKeySpec key = new SecretKeySpec(keyBytes, SymmetricAlgorithm); 94 byte[] decryptedBytes = DecryptSymmetric(Base64.getDecoder().decode(i.getText()), key); 95 i.setText(new String(decryptedBytes)); 96 } 97 } 75 98 } 76 99 -
trunk/src/org/expeditee/encryption/io/EncryptedExpWriter.java
r1399 r1400 22 22 import org.expeditee.gui.MessageBay; 23 23 import org.expeditee.io.ExpWriter; 24 import org.expeditee.items.Item; 24 25 import org.expeditee.items.Text; 25 26 import org.expeditee.settings.UserSettings; … … 60 61 61 62 @Override 63 public void outputFrame(Frame frame) throws IOException { 64 individualItemEncryption(frame); 65 super.outputFrame(frame); 66 } 67 68 @Override 62 69 protected void writeLine(String line) throws IOException { 63 70 // do not write empty lines … … 71 78 _writer.write(toWrite); 72 79 _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 } 73 97 } 74 98
Note:
See TracChangeset
for help on using the changeset viewer.