WorkspaceApplication.st
changeset 19423 a53f13ab2795
parent 19421 a89da38eeaeb
child 19424 397f4448289c
--- a/WorkspaceApplication.st	Mon Jan 20 21:02:47 2020 +0100
+++ b/WorkspaceApplication.st	Tue Jan 21 11:33:42 2020 +0100
@@ -2892,6 +2892,32 @@
     ^ key
 !
 
+askForEncryptionKeyFor:algorithm
+    |key rememberKey|
+
+    key := self objectAttributeAt:#rememberedSecretKey.
+    rememberKey := false.
+    Dialog 
+        withOptoutOption:[rememberKey := true] 
+        labelled:'Remember key during session' 
+        do:[
+            key := Dialog requestPassword:'Key' initialAnswer:key.
+        ].
+    key isEmptyOrNil ifTrue:[^ nil].
+
+    rememberKey ifTrue:[
+        self objectAttributeAt:#rememberedSecretKey put:key.
+    ] ifFalse:[
+        self removeObjectAttribute:#rememberedSecretKey.
+    ].
+
+    [key size < algorithm keySize] whileTrue:[
+        key := key , key.
+    ].
+    key := key copyTo:algorithm keySize.
+    ^ key
+!
+
 askForFilterBlock:message template:template rememberIn:nameOfClassVar
     |filterBlockString filterBlock dialog textHolder classVarValue|
 
@@ -2994,6 +3020,10 @@
     ]
 !
 
+encryptionAlgorithm
+    ^ SkipJackCipher.
+!
+
 inspectIt
     self inspectIt:false
 !
@@ -3192,22 +3222,24 @@
 !
 
 menuLoadEncryptedFrom
-    |key|
-
-    key := self askForEncryptionKey.
+    |algorithm key|
+
+    algorithm := self encryptionAlgorithm.
+
+    key := self askForEncryptionKeyFor:algorithm.
     key isNil ifTrue:[^ self].
 
     self 
         askForFile:'Load Encrypted From:'
         default:(self defaultFileNameForSave)
         forSave:false
-        thenDo:[:file :doAppend |
+        thenDo:[:file  |
             |ws contents lbl cipher crypt plaintext|
 
             contents := file asFilename binaryContents.
 
             ws := self selectedWorkspacesTextView.
-            cipher := SkipJackCipher new key:key mode:#CBC  .
+            cipher := algorithm new key:key mode:#CBC  .
             plaintext := (cipher decrypt:contents) asString.
             ws contents:plaintext.
             ws defaultFileNameForFileDialog:file asFilename baseName.
@@ -3245,9 +3277,11 @@
 !
 
 menuSaveEncryptedAs
-    |key|
-
-    key := self askForEncryptionKey.
+    |algorithm key|
+
+    algorithm := self encryptionAlgorithm.
+
+    key := self askForEncryptionKeyFor:algorithm.
     key isNil ifTrue:[^ self].
 
     self 
@@ -3255,11 +3289,13 @@
         default:(self defaultFileNameForSave)
         forSave:true
         thenDo:[:file :doAppend |
-            |ws contents lbl cipher crypt|
-
+            |bs ws contents lbl cipher crypt|
+
+            bs := algorithm blockSize.
             ws := self selectedWorkspacesTextView.
             contents := ws contentsAsString.
-            cipher := SkipJackCipher new key:key mode:#CBC  .
+            contents := contents , (String new:(contents size nextMultipleOf:bs)).
+            cipher := algorithm new key:key mode:#CBC  .
             crypt := cipher encrypt:contents.
             file asFilename writingFileDo:[:s |
                 s binary.