8

I have 7z on windows , and I want to encrypt 1 txt file with AES256 via 7z command line.

How can I do it please?

2 Answers2

7

To make the answer simple just use the switch -p which means Set Password with the default encryption which is AES.

The example below will encrypt the file or folder and prompt for a password:

  • 7z a -p Zip_File_Name File_2_zip.txt

The following example will auto add the password to the file for you.

  • 7z a -pPassword Zip_File_Name.7z File_2_Zip.txt

The other switches used above are:

7z a -p -mhe=on Zip_File_Name.7z File_2_Zip.txt

 -pPassword   ==  Auto add password without being prompted
 -mhe=on      ==  Means to encrypt the file names in archive too.
Pedro Lobito
  • 784
  • 1
  • 9
  • 19
1
7za u -mx -mhe -pPASSWORD ARCHIVE-FILE-NAME.7Z SOURCE-FILE-SPEC

Any time you use the .7z format, the file is AES-256 encrypted.

Arguments explained:

-pPASSWORD: setting the password PASSWORD.
u: update existing archive with new or modified files.
-mx: default compression level (5/6) - -mx1 (fastest) to -mx9.
-mhe: encryption of file headers (encrypted file names).

Rasalas
  • 103
  • 3
K7AAY
  • 9,512
  • 4
  • 33
  • 62
  • Can you please explain me what is the arguments `u` and `mx` and `mhe` ? Thank you – g319909.nwytg.coM Nov 22 '18 at 04:14
  • 1
    One issue per question, please, as per house rules. https://www.dotnetperls.com/7-zip-examples offers details. – K7AAY Nov 22 '18 at 23:28
  • 2
    Is it documented somewhere? I can see that the -mem switch (EncryptionMethodID) is available for zip type. Documented here: https://sevenzip.osdn.jp/chm/cmdline/switches/method.htm - but the documentation does not say anything about the cipher used for other types. So how do you know? – nagylzs Nov 13 '19 at 17:16
  • 2
    Asking what your answer means is not against the "house rules"! If anything, giving a literal answer to the question without any explaination is against them. – Arthur Tacca Sep 18 '20 at 20:14