Ignore:
Timestamp:
12/05/19 15:40:01 (4 years ago)
Author:
bnemhaus
Message:

Preperation for David's presentation.

File:
1 edited

Legend:

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

    r1485 r1494  
    3434public class Actions implements CryptographyConstants {
    3535       
    36         public static void SetSurrogateFor(Text surrogate, Text action) {
     36        public static void SetAsSurrogateFor(Text surrogate, Text action) {
    3737                Frame frame = DisplayController.getCurrentFrame();
    3838                String[] split = action.getText().split(" ");
     
    4848                        }
    4949                } else {
    50                         MessageBay.displayMessage("Usage: SetSurrogateFor Int, inject desired surrogate.");
     50                        FreeItems.getInstance().add(SetAsSurrogateForUsage());
    5151                }
    5252        }
     
    6969        }
    7070       
     71        public static Text JoinSecret() {
     72                return AuthJoinSecretUsage();
     73        }
     74       
    7175        public static Text JoinSecret(Text key) {
    7276                return AuthJoinSecret(key);
    7377        }
    7478       
     79        public static void Encrypt() {
     80                AuthEncryptUsage();
     81        }
     82       
    7583        public static void Encrypt(Text labelWithKey) {
    7684                AuthEncrypt(labelWithKey);
     85        }
     86       
     87        public static void Decrypt() {
     88                AuthDecryptUsage();
    7789        }
    7890       
     
    125137               
    126138                return key;
     139        }
     140       
     141        public static Text AuthJoinSecret() {
     142                return AuthJoinSecretUsage();
    127143        }
    128144               
     
    157173       
    158174        public static void AuthEncrypt(Text labelWithKey) {
    159                 // Obtain encryption key
    160                 String keyEncoded = labelWithKey.getData().get(0);
    161                 byte[] keyDecoded = Base64.getDecoder().decode(keyEncoded);
    162                 SecretKey key = new SecretKeySpec(keyDecoded, SymmetricAlgorithm);
    163                
    164                 // Perform encryption
    165                 Frame toEncrypt = FrameIO.LoadFrame(labelWithKey.getLink());
    166                 Collection<Text> textItems = toEncrypt.getTextItems();
    167                 for (Text t: textItems) {
    168                         byte[] encrypted = EncryptSymmetric(t.getText().getBytes(), key);
    169                         t.setText(Base64.getEncoder().encodeToString(encrypted));
    170                 }
    171                
    172                 // Save changes
    173                 FrameIO.SaveFrame(toEncrypt);
     175                try {
     176                        // Obtain encryption key
     177                        String keyEncoded = labelWithKey.getData().get(0);
     178                        byte[] keyDecoded = Base64.getDecoder().decode(keyEncoded);
     179                        SecretKey key = new SecretKeySpec(keyDecoded, SymmetricAlgorithm);
     180                       
     181                        // Perform encryption
     182                        Frame toEncrypt = FrameIO.LoadFrame(labelWithKey.getLink());
     183                        Collection<Text> textItems = toEncrypt.getTextItems();
     184                        for (Text t: textItems) {
     185                                byte[] encrypted = EncryptSymmetric(t.getText().getBytes(), key);
     186                                t.setText(Base64.getEncoder().encodeToString(encrypted));
     187                        }
     188                       
     189                        // Save changes
     190                        FrameIO.SaveFrame(toEncrypt);
     191                } catch (Exception e) {
     192                        FreeItems.getInstance().add(AuthEncryptUsage());
     193                }
    174194        }
    175195       
    176196        public static void AuthDecrypt(Text labelWithKey) {
    177                 // Obtain encryption key
    178                 String keyEncoded = labelWithKey.getData().get(0);
    179                 byte[] keyDecoded = Base64.getDecoder().decode(keyEncoded);
    180                 SecretKey key = new SecretKeySpec(keyDecoded, SymmetricAlgorithm);
    181                
    182                 // Perform decryption
    183                 Frame toDecrypt = FrameIO.LoadFrame(labelWithKey.getLink());
    184                 Collection<Text> textItems = toDecrypt.getTextItems();
    185                 for (Text t: textItems) {
    186                         byte[] decrypted = DecryptSymmetric(Base64.getDecoder().decode(t.getText().getBytes()), key);
    187                         t.setText(new String(decrypted));
    188                 }
    189                
    190                 // Save changes
    191                 FrameIO.SaveFrame(toDecrypt);
     197                try {
     198                        // Obtain encryption key
     199                        String keyEncoded = labelWithKey.getData().get(0);
     200                        byte[] keyDecoded = Base64.getDecoder().decode(keyEncoded);
     201                        SecretKey key = new SecretKeySpec(keyDecoded, SymmetricAlgorithm);
     202                       
     203                        // Perform decryption
     204                        Frame toDecrypt = FrameIO.LoadFrame(labelWithKey.getLink());
     205                        Collection<Text> textItems = toDecrypt.getTextItems();
     206                        for (Text t: textItems) {
     207                                byte[] decrypted = DecryptSymmetric(Base64.getDecoder().decode(t.getText().getBytes()), key);
     208                                t.setText(new String(decrypted));
     209                        }
     210                       
     211                        // Save changes
     212                        FrameIO.SaveFrame(toDecrypt);   
     213                } catch (Exception e) {
     214                        FreeItems.getInstance().add(AuthDecryptUsage());
     215                }
    192216        }
    193217       
     
    240264        }
    241265       
     266        private static Text AuthJoinSecretUsage() {
     267                String nl = System.getProperty("line.separator");
     268                String tab = "   ";
     269                StringBuilder message = new StringBuilder("Usage: " + nl);
     270                message.append(tab + "With Text Item attached to cursor: " + nl);
     271                message.append(tab + tab + "Content matches pattern \"<SecretName> <Amount of Coperation Required> <Total Number of Shares>\"" + nl);
     272                message.append(tab + tab + "Data contains <Amount of Coperation Required> partial keys" + nl);
     273                message.append(tab + "Left click on this action." + nl);
     274                message.append(tab + "Resulting Text Item will contain joined key in data.");
     275                return generateUsageText(message);
     276        }
     277       
    242278        private static Text AuthSplitSecretUsage() {
    243279                String nl = System.getProperty("line.separator");
     
    248284                message.append(tab + tab + "Context Example: \"SecretName 3 Sandra John Billy Sally Sam Tim\"" + nl);
    249285                message.append(tab + tab + "Data contains key data" + nl);
    250                 message.append(tab + "Middle click on this action." + nl);
     286                message.append(tab + "Left click on this action." + nl);
    251287                message.append(tab + "Resulting Text Item will contain shares in data.");
    252288                return generateUsageText(message);
     
    261297                message.append(tab + tab + "Content represents the desired label name for the generated secret." + nl);
    262298                message.append(tab + tab + "This action will overwrite any existing data." + nl);
    263                 message.append(tab + "Middle click on this action." + nl);
     299                message.append(tab + "Left click on this action." + nl);
    264300                message.append(tab + "Text Item will now contain a full key in its data." + nl);
    265301                message.append(tab + "Resulting Text Item is now a Secret and can be placed on secrets frame.");
     302                return generateUsageText(message);
     303        }
     304       
     305        private static Text AuthEncryptUsage() {
     306                String nl = System.getProperty("line.separator");
     307                String tab = "   ";
     308                StringBuilder message = new StringBuilder("Usage: " + nl);
     309                message.append(tab + "Note: this action was used for demonstration purposes earlier in development." + nl);
     310                message.append(tab + "(It can now be considered deprecated by Encryption Label and surrogate functionality)" + nl);
     311                message.append(tab + "With Text Item attached to cursor: " + nl);
     312                message.append(tab + tab + "Data contains key data." + nl);
     313                message.append(tab + tab + "Must be linked to frame you wish to encrypt." + nl);
     314                message.append(tab + "Left click on this action." + nl);
     315                message.append(tab + "Content on linked frame will now be encrypted.");
     316                return generateUsageText(message);
     317        }
     318       
     319        private static Text AuthDecryptUsage() {
     320                String nl = System.getProperty("line.separator");
     321                String tab = "   ";
     322                StringBuilder message = new StringBuilder("Usage: " + nl);
     323                message.append(tab + "Note: this action was used for demonstration purposes earlier in development." + nl);
     324                message.append(tab + "(It can now be considered deprecated by Encryption Label and surrogate functionality)" + nl);
     325                message.append(tab + "With Text Item attached to cursor: " + nl);
     326                message.append(tab + tab + "Data contains key data." + nl);
     327                message.append(tab + tab + "Must be linked to frame that was previously encrypted." + nl);
     328                message.append(tab + "Left click on this action." + nl);
     329                message.append(tab + "Content on linked frame will now be decrypted.");
     330                return generateUsageText(message);
     331        }
     332       
     333        private static Text SetAsSurrogateForUsage() {
     334                String nl = System.getProperty("line.separator");
     335                String tab = "   ";
     336                StringBuilder message = new StringBuilder("Usage: " + nl);
     337                message.append(tab + "Change arugment to be the ID of the desired primary item." + nl);
     338                message.append(tab + "(An items ID is available in its extracted properties)" + nl);
     339                message.append(tab + "With Text Item attached to cursor: " + nl);
     340                message.append(tab + tab + "Attached Item is desired surrogate." + nl);
     341                message.append(tab + "Left click on this action." + nl);
     342                message.append(tab + "Item will respect surrogate mode once placed on frame." + nl);
    266343                return generateUsageText(message);
    267344        }
Note: See TracChangeset for help on using the changeset viewer.