Changeset 1494 for trunk/src/org/expeditee/encryption/Actions.java
- Timestamp:
- 12/05/19 15:40:01 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/encryption/Actions.java
r1485 r1494 34 34 public class Actions implements CryptographyConstants { 35 35 36 public static void Set SurrogateFor(Text surrogate, Text action) {36 public static void SetAsSurrogateFor(Text surrogate, Text action) { 37 37 Frame frame = DisplayController.getCurrentFrame(); 38 38 String[] split = action.getText().split(" "); … … 48 48 } 49 49 } else { 50 MessageBay.displayMessage("Usage: SetSurrogateFor Int, inject desired surrogate.");50 FreeItems.getInstance().add(SetAsSurrogateForUsage()); 51 51 } 52 52 } … … 69 69 } 70 70 71 public static Text JoinSecret() { 72 return AuthJoinSecretUsage(); 73 } 74 71 75 public static Text JoinSecret(Text key) { 72 76 return AuthJoinSecret(key); 73 77 } 74 78 79 public static void Encrypt() { 80 AuthEncryptUsage(); 81 } 82 75 83 public static void Encrypt(Text labelWithKey) { 76 84 AuthEncrypt(labelWithKey); 85 } 86 87 public static void Decrypt() { 88 AuthDecryptUsage(); 77 89 } 78 90 … … 125 137 126 138 return key; 139 } 140 141 public static Text AuthJoinSecret() { 142 return AuthJoinSecretUsage(); 127 143 } 128 144 … … 157 173 158 174 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 } 174 194 } 175 195 176 196 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 } 192 216 } 193 217 … … 240 264 } 241 265 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 242 278 private static Text AuthSplitSecretUsage() { 243 279 String nl = System.getProperty("line.separator"); … … 248 284 message.append(tab + tab + "Context Example: \"SecretName 3 Sandra John Billy Sally Sam Tim\"" + nl); 249 285 message.append(tab + tab + "Data contains key data" + nl); 250 message.append(tab + " Middleclick on this action." + nl);286 message.append(tab + "Left click on this action." + nl); 251 287 message.append(tab + "Resulting Text Item will contain shares in data."); 252 288 return generateUsageText(message); … … 261 297 message.append(tab + tab + "Content represents the desired label name for the generated secret." + nl); 262 298 message.append(tab + tab + "This action will overwrite any existing data." + nl); 263 message.append(tab + " Middleclick on this action." + nl);299 message.append(tab + "Left click on this action." + nl); 264 300 message.append(tab + "Text Item will now contain a full key in its data." + nl); 265 301 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); 266 343 return generateUsageText(message); 267 344 }
Note:
See TracChangeset
for help on using the changeset viewer.