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

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

Re: Encrypt all files in the "Documents" folder

Post by Klaus » Tue May 03, 2022 12:24 pm

Why the unneccessary detour with -> the longfilepath?
From the dictionary:
...
Use the longFilePath function to get the long equivalent of a short file path passed from the command line.
...
"answer file..." is an LC command, nothing to do with the command line, and returns the long file path already.

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

Re: Encrypt all files in the "Documents" folder

Post by liveCode » Tue May 03, 2022 2:26 pm

I work with android and desktop this code I edited from mimu

Code: Select all

on mouseUp
   local XYZ,tencrypted
   answer file "Choose an RTF file to import"
   put it into FDA
   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
      if the result = "cancel" 
      then exit mouseUp
      else
         
         put tencrypted into URL ("binfile:"&FDA)
         get the longFilePath of FDA
         set the itemDelimiter to slash
         set the defaultFolder to item 1 to -2 of the longFilePath of FDA
      end if
   end if
end mouseUp
The code itself works but I want it to run this code on the document folder because that's where the user's result is stored

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

Re: Encrypt all files in the "Documents" folder

Post by Klaus » Tue May 03, 2022 2:41 pm

1.

Code: Select all

...
answer file "..."
...
will not work on mobile!

2.

Code: Select all

...
put URL ("binfile:" & it) into XYZ
encrypt XYZ using "aes-256-cbc" with password "richmond62" 
put it into tencrypted
if the result = "cancel" 
then exit mouseUp
else
...
The last "if the result = "cancel" does not make any sense at this place in the script!

3. You will need to set a marker, that all files have already been encrypted, or you will encrypt
already encrypted files and be surprised if you try to DEcrypt them later.

Conclusion:
You should encrypt "the user's result", which will probably be in a variable, BEFORE you write them to
a file in the users documents folder!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Encrypt all files in the "Documents" folder

Post by jacque » Tue May 03, 2022 5:17 pm

If this is for Android, the user won't have easy access to the files in the document folder, they are sandboxed. Even a file manager can't see them, though a user who has rooted their phone could . So you may not need to encrypt them at all. It's rare these days for users to root their phones.

If you do want to encrypt anyway, use the files() function to get the list of files and encrypt each one inside a repeat loop.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Encrypt all files in the "Documents" folder

Post by liveCode » Wed May 04, 2022 2:31 pm

Can you give me a code that encrypts these files?

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

Re: Encrypt all files in the "Documents" folder

Post by richmond62 » Wed May 04, 2022 3:54 pm

Can you give me a code that encrypts these files?
That is exactly what has been explained in previous posts.

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

Re: Encrypt all files in the "Documents" folder

Post by liveCode » Wed May 04, 2022 3:57 pm

I succeeded

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”