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
  • 478

3 Answers3

2

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

SparedWhisle
  • 4,393
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:

0

You could encrypt your folder twice to hide your file names:

type="zip"; file="your-folder"; password="your-password"; # You also could use other formats.

7z a -t"$type" "$file.$type" -p"$password" "$file" 7z a -t"$type" "$file.$type.$type" -p"$password" "$file.$type"

Then the file "your-folder.zip.zip" is what you want.

Big Shield
  • 101
  • 1