TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Partially encrypt a file based on its HEREDOCs

38 pointsby higginsabout 3 years ago
Hi HN!<p>I wrote a tool that partially encrypts files based on the presence of a HEREDOC.<p>Check it out: https:&#x2F;&#x2F;github.com&#x2F;higgins&#x2F;privatize<p>When added to a git repo, it will automatically transparently encrypt&#x2F;decrypt files you want privatized.<p>For example if you configured your repo to privatize the file `example.txt`, you could write:<p><pre><code> ``` Today I a burrito. &lt;&lt;PRIVATE I was on the toilet for hours. PRIVATE I got a lot of reading done. ``` </code></pre> but when git-commit&#x27;ed would become:<p><pre><code> ``` Today I a burrito. &lt;&lt;PRIVATE xuJ0fld2vmNWaVLogTIufmWsiFso PRIVATE I got a lot of reading done. ``` </code></pre> Diffing works as you expect (on the unencrypted source) and only those with the `privatize` symmetric key would be able to unlock and decrypt these files.<p>Why did I do this?<p>I keep a public log of what I plan to accomplish and what I&#x27;m working on both personally&#x2F;professionally. At the end of the day, I write a summary of everything that happened. Naturally, there are some details of my life that should be kept private (details of too-be-launched projects, sensitive family events, etc).<p>It&#x27;s helpful for me to track everything in one file so as to keep the day&#x27;s context together.<p>Would love to know what you think! Justin

7 comments

nnfabout 3 years ago
This is a neat idea. I wrote something similar recently but with the aim of encrypting sensitive values (like API keys) in YAML config files, for similar reasons — so people without the key can see most of the config but not the secret parts. The script is then used by an automated deployment process to decrypt the sensitive values when the config file is moved into place.
评论 #30705167 未加载
higginsabout 3 years ago
FYI: this was inspired by the great `git-crypt` (<a href="https:&#x2F;&#x2F;github.com&#x2F;AGWA&#x2F;git-crypt" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;AGWA&#x2F;git-crypt</a>)<p>More on my motivations here: <a href="https:&#x2F;&#x2F;encapsulate.me&#x2F;writing&#x2F;Privatize.html" rel="nofollow">https:&#x2F;&#x2F;encapsulate.me&#x2F;writing&#x2F;Privatize.html</a>
amenghraabout 3 years ago
I might not have properly understood this tool, but is the encryption key and iv getting reused? If so, it&#x27;s usually quite unsafe to reuse IVs (but consult a cryptographer, YMMV). Feels weird to stuff the IV with the key, it should live with the ciphertext.<p>(I only glanced at the code for a few minutes, so I could be wrong: <a href="https:&#x2F;&#x2F;github.com&#x2F;higgins&#x2F;privatize&#x2F;blob&#x2F;0.1.1&#x2F;index.js#L73" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;higgins&#x2F;privatize&#x2F;blob&#x2F;0.1.1&#x2F;index.js#L73</a>)
评论 #30705101 未加载
oh_sighabout 3 years ago
My fear of using something like this would be to accidentally mess up the format (&lt;PRIVATE, &lt;&lt;PIRVATE, etc), and accidentally commit my private stuff in plaintext. Similarly, if I misconfigure my .gitattributes, I might try to use this on a file which the privatizer program doesn&#x27;t even get run over.
评论 #30705508 未加载
kkfxabout 3 years ago
Nice, but not new :-)<p>See Emacs&#x2F;org-mode org-encrypt-entry and org-decrypt-entry, it&#x27;s easy to encrypt and decrypt via GNUPG text under a heading + the benefit of org-mode outlining witch dramatically improve readability.
评论 #30718723 未加载
klyrsabout 3 years ago
Do you check that the sentinel string PRIVATE does not occur in the encrypted data?
评论 #30705135 未加载
mdanielabout 3 years ago
Yikes, do all filters do that? <a href="https:&#x2F;&#x2F;github.com&#x2F;higgins&#x2F;privatize&#x2F;blob&#x2F;0.1.1&#x2F;index.js#L98" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;higgins&#x2F;privatize&#x2F;blob&#x2F;0.1.1&#x2F;index.js#L98</a><p>Also, it&#x27;s 2022 and I still have to remind people not to commit binary assets into git repos, as the repo will grow without bound: <a href="https:&#x2F;&#x2F;github.com&#x2F;higgins&#x2F;privatize&#x2F;tree&#x2F;main&#x2F;release" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;higgins&#x2F;privatize&#x2F;tree&#x2F;main&#x2F;release</a><p>That&#x27;s the very problem that GitHub Releases were designed to address, and has the extra awesome benefit of using (currently) AWS S3 for distribution, which is almost certainly going to be faster and place less load upon github.com than ...&#x2F;raw&#x2F;main&#x2F;release&#x2F;whatever.exe<p>Also, while the Brew tap indicates your code is ISC, there is no license file in your repo: <a href="https:&#x2F;&#x2F;github.com&#x2F;higgins&#x2F;homebrew-privatize&#x2F;blob&#x2F;main&#x2F;Formula&#x2F;privatize.rb#L8" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;higgins&#x2F;homebrew-privatize&#x2F;blob&#x2F;main&#x2F;Form...</a>
评论 #30705229 未加载
评论 #30703935 未加载