#BUGFIX by exept
class: WorkspaceApplication
changed:
#menuLoadEncryptedFrom
#menuSaveEncryptedAs
--- a/WorkspaceApplication.st Tue Jan 21 11:33:42 2020 +0100
+++ b/WorkspaceApplication.st Tue Jan 21 19:44:33 2020 +0100
@@ -3234,13 +3234,19 @@
default:(self defaultFileNameForSave)
forSave:false
thenDo:[:file |
- |ws contents lbl cipher crypt plaintext|
+ |ws blob pos1 pos2 contents lbl cipher crypt plaintext szString sz start|
contents := file asFilename binaryContents.
ws := self selectedWorkspacesTextView.
cipher := algorithm new key:key mode:#CBC .
- plaintext := (cipher decrypt:contents) asString.
+ blob := (cipher decrypt:contents) asString.
+ pos1 := (blob indexOf:(Character null))+1.
+ pos2 := (blob indexOf:(Character space) startingAt:pos1)-1.
+ szString := blob copyFrom:pos1 to:pos2.
+ sz := Integer readFrom:szString.
+
+ plaintext := blob copyFrom:65 to:(65+sz-1).
ws contents:plaintext.
ws defaultFileNameForFileDialog:file asFilename baseName.
]
@@ -3289,17 +3295,27 @@
default:(self defaultFileNameForSave)
forSave:true
thenDo:[:file :doAppend |
- |bs ws contents lbl cipher crypt|
+ |bs ws contents lbl cipher crypted rndBytes pos|
bs := algorithm blockSize.
ws := self selectedWorkspacesTextView.
contents := ws contentsAsString.
+
+ "/ place the size info at some random position within the random bytes
+ rndBytes := ByteArray withAll:((Random next:64 between:1 and:255) collect:#rounded).
+ pos := Random nextIntegerBetween:20 and:50.
+ rndBytes at:pos put:0.
+ rndBytes replaceFrom:pos+1 with:(contents size printString , ' ').
+ rndBytes := rndBytes asString.
+
+ contents := rndBytes , contents.
contents := contents , (String new:(contents size nextMultipleOf:bs)).
- cipher := algorithm new key:key mode:#CBC .
- crypt := cipher encrypt:contents.
+ cipher := algorithm new key:key mode:#CBC.
+
+ crypted := cipher encrypt:contents.
file asFilename writingFileDo:[:s |
s binary.
- s nextPutAll:crypt.
+ s nextPutAll:crypted.
].
ws defaultFileNameForFileDialog:file asFilename baseName.
]