Page 1 of 2

Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 6:58 pm
by liveCode
I have all kinds of text files in the "Documents" folder(specialfolderpath("documents")) and so that they can not change the text in the file I want to encrypt all the files in the folder
how do I do it?
Thank you

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 7:03 pm
by richmond62
I think you have to do that from outside LiveCode,
and it will depend on what operating system you are using.

Why is the text in those documents not stored inside your LiveCode stack?

This would probably make things simpler.

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 7:10 pm
by liveCode
Text files are stored here:

Code: Select all

specialfolderpath("documents")
And is not stored within the LIVECODE because the text changes

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 7:17 pm
by richmond62
because the text changes
If the text changes I don't see how it can be encrypted.

However, if you store the text in fields in a substack of a standalone it can be saved and will be
inaccessible to your customenrs.

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 7:25 pm
by liveCode
Can't do that with the "Encrypt" command?

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 7:29 pm
by Klaus
There is definitively no reason why that should not work! 8)

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 7:32 pm
by richmond62
Klaus is right, and I am wrong:
-
SShot 2022-05-02 at 21.31.33.png

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 7:51 pm
by liveCode
So how do I do that?

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 7:54 pm
by richmond62
Well you can start by reading all the stuff in the Dictionary
under ENCRYPT . . .

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 7:57 pm
by liveCode
I know how to encrypt text
But I do not know how to encrypt all the text files in "Documents"

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 8:03 pm
by Klaus
Read the text file into a variable, encrypt it and write it back to file. 8)

Important:
"encrypt" returns BINARY data, so you need to write it back to "url("BINFILE: ...")
And later read it in also as BINFILE!

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 8:30 pm
by richmond62
SShot 2022-05-02 at 22.28.06.png
-
Well, I tried and went wrong somewhere:
-

Code: Select all

on mouseUp
   answer file "Choose an RTF file to import"
   if the result = "cancel" 
   then exit mouseUp
   else
      put URL ("binfile:" & it) into XYZ
      encrypt XYZ using "aes-256-cbc" with password "richmond62" 
      ask file "Choose where you wish to export your text"
      if the result = "cancel" 
      then exit mouseUp
      else
         put XYZ into URL ("binfile:" & it)
         get the longFilePath of it
         set the itemDelimiter to slash
         set the defaultFolder to item 1 to -2 of the longFilePath of it
      end if
      end if
   end mouseUp
As the resulting file was completely unencrypted. :(

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 8:39 pm
by stam
Klaus wrote:
Mon May 02, 2022 8:03 pm
Read the text file into a variable, encrypt it and write it back to file. 8)

Important:
"encrypt" returns BINARY data, so you need to write it back to "url("BINFILE: ...")
And later read it in also as BINFILE!
Or run it through base64 to convert encrypted binary data to text which you can then save as a normal text file (or transmit online)

Re: Encrypt all files in the "Documents" folder

Posted: Mon May 02, 2022 10:01 pm
by FourthWorld
Desktop or mobile?

And is the goal to provide a high level of protection for extremely sensitive information, or just to prevent the user from accidentally altering their own files?

Re: Encrypt all files in the "Documents" folder

Posted: Tue May 03, 2022 12:22 am
by mimu
the result of the encrypt command is inside the it variable!

Code: Select all

on mouseUp
   local XYZ,tencrypted
   answer file "Choose an RTF file to import"
   if the result = "cancel" then 
      exit mouseUp
   else
      put URL ("binfile:" & it) into XYZ
      encrypt XYZ using "aes-256-cbc" with password "richmond62" 
      put it into tencrypted
      ask file "Choose where you wish to export your text"
      if the result = "cancel" 
      then exit mouseUp
      else
         put tencrypted into URL ("binfile:" & it)
         get the longFilePath of it
         set the itemDelimiter to slash
         set the defaultFolder to item 1 to -2 of the longFilePath of it
      end if
   end if
end mouseUp