Encrypt all files in the "Documents" folder

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

Encrypt all files in the "Documents" folder

Post by liveCode » Mon May 02, 2022 6:58 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Encrypt all files in the "Documents" folder

Post by richmond62 » Mon May 02, 2022 7:03 pm

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.

liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

Re: Encrypt all files in the "Documents" folder

Post by liveCode » Mon May 02, 2022 7:10 pm

Text files are stored here:

Code: Select all

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Encrypt all files in the "Documents" folder

Post by richmond62 » Mon May 02, 2022 7:17 pm

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.

liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

Re: Encrypt all files in the "Documents" folder

Post by liveCode » Mon May 02, 2022 7:25 pm

Can't do that with the "Encrypt" command?

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Encrypt all files in the "Documents" folder

Post by Klaus » Mon May 02, 2022 7:29 pm

There is definitively no reason why that should not work! 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Encrypt all files in the "Documents" folder

Post by richmond62 » Mon May 02, 2022 7:32 pm

Klaus is right, and I am wrong:
-
SShot 2022-05-02 at 21.31.33.png

liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

Re: Encrypt all files in the "Documents" folder

Post by liveCode » Mon May 02, 2022 7:51 pm

So how do I do that?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Encrypt all files in the "Documents" folder

Post by richmond62 » Mon May 02, 2022 7:54 pm

Well you can start by reading all the stuff in the Dictionary
under ENCRYPT . . .

liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

Re: Encrypt all files in the "Documents" folder

Post by liveCode » Mon May 02, 2022 7:57 pm

I know how to encrypt text
But I do not know how to encrypt all the text files in "Documents"

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Encrypt all files in the "Documents" folder

Post by Klaus » 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!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Encrypt all files in the "Documents" folder

Post by richmond62 » Mon May 02, 2022 8:30 pm

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. :(

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Encrypt all files in the "Documents" folder

Post by stam » Mon May 02, 2022 8:39 pm

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)

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9824
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Encrypt all files in the "Documents" folder

Post by FourthWorld » Mon May 02, 2022 10:01 pm

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?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mimu
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 76
Joined: Tue Mar 05, 2013 7:00 pm
Location: Berlin
Contact:

Re: Encrypt all files in the "Documents" folder

Post by mimu » Tue May 03, 2022 12:22 am

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

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”