Is it possible to encrypt all files in a folder including their file names but totally without compression using 7zip?

1

I have a folder with several files:

file1
file2
file3

I want to encrypt them all with AES including the file names so the output should be something like this:

kjk437fjk437
3k4jn34jk
j34nkj34

But I do not want to apply any compression at all.

Is it possible to do this with 7zip? I am using Debian and looking for Terminal based solutions only.

Edit: I also want to be able to get the filename back after decryption.

Vesa

Posted 2019-01-21T05:54:28.080

Reputation: 310

Please clarify your requirements: why do you need to avoid compression? – user1686 – 2019-01-21T08:17:03.273

Did you think of encrypting the filenames in an extra step as simple string encryption? – Julian F. Weinert – 2019-01-21T16:43:02.663

Answers

1

You probably just want to hide the filename instead of to encrypt it, so something like the following should do:

for file in ./*;do 
  7z a $RANDOM-$RANDOM.7z -m1=copy -mhe -psecret "$file"; 
  rm "$file" 
done

-m1=copy means use copy method, so no compression.
-mhe means encrypt header, so without password one cannot view filenames inside the 7z file.
-psecret sets password to secret

David Dai

Posted 2019-01-21T05:54:28.080

Reputation: 2 833

Interesting. But how can I get the filename back when I want to decrypt again? – Vesa – 2019-01-21T10:03:57.343

@Vesa the original filename is stored in the archive. You get the original file + filename back just by extracting it. – David Dai – 2019-01-21T21:05:01.167

And this also AES encrypts the content of the file? – Vesa – 2019-01-21T21:31:21.617

@Vesa I believe it does. – David Dai – 2019-01-21T21:48:20.103

I will test it soon – Vesa – 2019-01-22T00:10:56.230

Seems to work. Will apply some further testing. By the way I read somewhere that it's not recommended to use 7zip for backups because owner/group is not stored. What does it mean and can I still use 7zip for backup? – Vesa – 2019-01-22T02:23:29.727

@Vesa you are probably right. I believe 7zip was originally created for windows, then later ported to Linux, so it's support for permission/ownership might not be very good. But I'm not an expert on that, so cannot provide more details. I would recommend you do some research yourself, I'm sure there are already plenty of resources out there(or here on stackexchange) . – David Dai – 2019-01-22T02:33:27.177

0

Is 7zip a must? Choose the right tool. EncFS seems to be it.

  1. Install it. In Debian: apt-get install encfs.
  2. Create two directories: mkdir encrypted mountpoint.

  3. Run the tool:

    encfs "$PWD/encrypted" "$PWD/mountpoint"
    

    Note you need $PWD/ instead of ./ because encfs doesn't accept relative paths (unless -f is used).

  4. Proceed as instructed to choose encryption, password.

  5. Copy or move all directories and files you want to encrypt to ./mountpoint. Encrypted directories and files will appear in the ./encrypted directory.

  6. Unmount:

    fusermount -u ./mountpoint
    

You can now copy/move/rename/tar/whatever the ./encrypted directory as a whole. Note there is a hidden .xml file inside. The file includes the (password protected) key which is crucial, so don't lose it. It's possible to store the file separetely (read about ENCFS6_CONFIG variable in man 1 encfs).

To access the original files, repeat step 3, provide the right password. Work with files under the chosen mountpoint: read, add, remove, modify, anything goes. Finally unmount with fusermount -u like in step 6.

Notes:

Kamil Maciorowski

Posted 2019-01-21T05:54:28.080

Reputation: 38 429

Cannot use encfs on this device, otherwise I would as I used to before. – Vesa – 2019-01-21T10:02:22.997

@Vesa It's somewhat disappointing you knew about encfs and you knew you can't use it now, still you didn't explicitly ruled it out. I did notice you're asking about a 7zip solution; but sticking to some tool is often a Y in XY problem, while good answers should concentrate on X and this is what I was trying to do. The answer will stay (with other users in mind), unless you change the question so it clearly says encfs is not an option. Regardless, I do hope you'll get an answer that fits you. Good luck.

– Kamil Maciorowski – 2019-01-21T10:45:14.227