<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>7zip on Geek Cabinet</title>
    <link>https://geekcabi.net/tags/7zip/</link>
    <description>Recent content in 7zip on Geek Cabinet</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Sun, 27 Aug 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://geekcabi.net/tags/7zip/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>But What if I HAVE to Encrypt with 7zip?</title>
      <link>https://geekcabi.net/posts/encrypt-with-7z/</link>
      <pubDate>Sun, 27 Aug 2023 00:00:00 +0000</pubDate>
      
      <guid>https://geekcabi.net/posts/encrypt-with-7z/</guid>
      <description>&lt;p&gt;Yes, I know I updated the &lt;a href=&#34;https://geekcabi.net/tools/#file-encryption&#34;&gt;tools page&lt;/a&gt; and now recommend &lt;strong&gt;against&lt;/strong&gt; encrypting with 7zip. But sometimes we have to do things we don&amp;rsquo;t &lt;strong&gt;want&lt;/strong&gt; to do.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>Yes, I know I updated the <a href="/tools/#file-encryption">tools page</a> and now recommend <strong>against</strong> encrypting with 7zip. But sometimes we have to do things we don&rsquo;t <strong>want</strong> to do.</p>
<p>Like eat our vegetables. Wait. No, that&rsquo;s actually <strong>good</strong> for you.</p>
<p>Whatever.</p>
<p>You get the idea.</p>
<p>Encrypting a file with 7zip is simple. Use the <code>-p</code> option:</p>
<pre tabindex="0"><code>~$ 7z a archive.7z -pSTRONG_PASSWORD_THAT_IS_REALLY_LONG_HERE! folder/

7-Zip [64] 17.04 : Copyright (c) 1999-2021 Igor Pavlov : 2017-08-28
p7zip Version 17.04 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,8 CPUs x64)

Scanning the drive:
1 folder, 4 files, 0 bytes

Creating archive: archive.7z

Items to compress: 5

    
Files read from disk: 0
Archive size: 186 bytes (1 KiB)
Everything is Ok
</code></pre><p>I have always loved 7zip&rsquo;s attempt to make me feel better.</p>
<p>&ldquo;Don&rsquo;t worry. Everything is Ok.&rdquo; :thumbs_up: :grinning_squinting_face:</p>
<blockquote>
<p><strong>Note:</strong>
There is <strong>no space</strong> between the option and the password. That&rsquo;s an oddity with 7z that I just don&rsquo;t see with many other CLI tools.</p>
</blockquote>
<p>You may notice, however, that when you go to list the contents of the archive, the folder and file names are listed <strong>without</strong> prompting for the password!</p>
<pre tabindex="0"><code>~$ 7z l archive.7z                   

7-Zip [64] 17.04 : Copyright (c) 1999-2021 Igor Pavlov : 2017-08-28
p7zip Version 17.04 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,8 CPUs x64)

Scanning the drive for archives:
1 file, 186 bytes (1 KiB)

Listing archive: archive.7z

--
Path = archive.7z
Type = 7z
Physical Size = 186
Headers Size = 186
Solid = -
Blocks = 0

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2023-08-23 16:01:10 D....            0            0  folder
2023-08-23 16:01:10 ....A            0            0  folder/bank_info.xlsx
2023-08-23 16:01:10 ....A            0            0  folder/classified.txt
2023-08-23 16:01:10 ....A            0            0  folder/file1.txt
2023-08-23 16:01:10 ....A            0            0  folder/file2.txt
------------------- ----- ------------ ------------  ------------------------
2023-08-23 16:01:10                  0            0  4 files, 1 folders
</code></pre><p>Showing folder and file names without requiring the password is probably not acceptable for encrypted files. (Then again, ideally we wouldn&rsquo;t be using 7zip for encryption, but&hellip;.I already made that point.)</p>
<p>To encrypt the folder and file names, too, we need to use an option that only shows up on the <code>man</code> page of 7zip and not in the CLI help output:</p>
<pre tabindex="0"><code>-mhe=on|off
   7z format only : enables or disables archive header encryption (Default : off)
</code></pre><p>So all of this only works on the 7z format vs traditional zip, etc&hellip;</p>
<p>With this, our example changes to:</p>
<pre tabindex="0"><code>7z a archive.7z -mhe=on -pSTRONG_PASSWORD_THAT_IS_REALLY_LONG_HERE! folder/
</code></pre><p>The output is the same until the file contents are listed:</p>
<pre tabindex="0"><code>7z l archive.7z                           

7-Zip [64] 17.04 : Copyright (c) 1999-2021 Igor Pavlov : 2017-08-28
p7zip Version 17.04 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,8 CPUs x64)

Scanning the drive for archives:
1 file, 221 bytes (1 KiB)

Listing archive: archive.7z


Enter password (will not be echoed):
--
Path = archive.7z
Type = 7z
Physical Size = 221
Headers Size = 221
Solid = -
Blocks = 0

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2023-08-23 16:01:10 D....            0            0  folder
2023-08-23 16:01:10 ....A            0            0  folder/bank_info.xlsx
2023-08-23 16:01:10 ....A            0            0  folder/classified.txt
2023-08-23 16:01:10 ....A            0            0  folder/file1.txt
2023-08-23 16:01:10 ....A            0            0  folder/file2.txt
------------------- ----- ------------ ------------  ------------------------
2023-08-23 16:01:10                  0            0  4 files, 1 folders
</code></pre><p>One other thing to note: encrypting a file in this manner will leave the password in your shell history file. I will leave as an exercise to the reader the following search: &ldquo;<a href="https://duckduckgo.com/?q=histcontrol%3Dignorespace" rel="noopener" target="_blank" class="external">HISTCONTROL=ignorespace</a>&rdquo; &#x1f60f;</p>]]></content:encoded>
    </item>
    
  </channel>
</rss>
