Encrypt Module

The encrypt module allows encrypting or protecting partial contents.

Module
github.com/hugomods/encrypt
GitHub Stars Used By Used By Used By Used By

How it Works?

This module ships with a shortcode and a CLI tool, to walk though the Hugo generated files and encrypt the content in AES-256-GCM.

graph TD;
  content[Protect content via shortcode `encrypt`]-->build;
  build[Build site, i.e. `hugo --minify --gc ...`]-->encrypt[Encrypt content via `$HOME/go/bin/encrypt`];

The difference between this and normal build is that, you need to combine the CLI tool with Hugo, i.e.

1hugo && $HOME/go/bin/encrypt

Features

  • Partial encryption, protect the key part, SEO friendly.
  • Remember password to auto decrypt.

Notes

There are some stuff you should pay attention to.

  • Keep your repo (source files) private, since the raw password and content are plaintext.
  • Execute the CLI tool after building the site, otherwise the generated files are not encrypted.

Installation

To get the CLI tool, you can either download from the releases or install from source.

Install from Source

1go install github.com/hugomods/encrypt/commands/encrypt@latest

Then you’re able to access the command

1$HOME/go/bin/encrypt

Integrate with Theme

This section is for developers to integrate this module into their themes.

Import the Module

hugo.yaml

1module:
2  imports:
3  - path: github.com/hugomods/encrypt

hugo.toml

1[module]
2  [[module.imports]]
3    path = 'github.com/hugomods/encrypt'

hugo.json

1{
2   "module": {
3      "imports": [
4         {
5            "path": "github.com/hugomods/encrypt"
6         }
7      ]
8   }
9}

Import the CSS

Please skip this step if your theme supports HugoPress, such as HB Framework themes.

1{{ partial "encrypt/assets/css" . }}

Import the JS

Please skip this step if your theme supports HugoPress, such as HB Framework themes.

1{{ partial "encrypt/assets/js" . }}

Configuration

ParameterTypeRequiredDefaultDescription
passwordstringY-The default password.
storagestringYsessionsession (SessionStorage) or local (LocalStorage).

hugo.yaml

1params:
2  encrypt:
3    password: DEFAULT_PASSWORD
4    storage: session

hugo.toml

1[params]
2  [params.encrypt]
3    password = 'DEFAULT_PASSWORD'
4    storage = 'session'

hugo.json

1{
2   "params": {
3      "encrypt": {
4         "password": "DEFAULT_PASSWORD",
5         "storage": "session"
6      }
7   }
8}

Usage

This section shows users how to protect their contents, please make sure you’ve imported the module.

Default password: hugomods.com.

Encrypt Raw Content

1{{< encrypt >}}
2Hello World!
3{{< /encrypt >}}

The following content is protected.

48160763ec34b7ef-883bbdf5af362664f00f771b-ba42199ce171cacf5add95b16b24f0c093987b95a208567681269235646962236d46138cc866ad31cccc7d8d320d9913b6958f9db396ed36f93a45f4334a8eefba16d672eeaf31b131168a6b389d8c6bc0a30ae76070c201bc9b02efa74bfacb57bdc162a98311a8b7d0e648374d

Encrypt Markdown Content

1{{% encrypt %}}
2**Hello World!**
3{{% /encrypt %}}

The following content is protected.

23a3ef728abf0a2b-6f697b454f396790d294fa41-9ce9abab0c25c9248bc54244f5e77f5078378d3c42d39ec56405b4f56e085949a367a3e1c76b8b9eaf567a548890ead3c797cfba4139a125d906afa3b77329949e537edae12bed17545130719923765b35b342a60722e2cf924556ca57b57a30a12748be4645bb49f2a82058882bdba713d1e6fb21f2ecc24ca8a9bc55f5da90bf97e708e510

Encrypt Content with Specified Password

1{{% encrypt foo %}}
2**Bar!**
3{{% /encrypt %}}

The following content is protected.

6ef7e64d065b0d05-0a5bee9d7037684db15caddd-7747c90fe070929837f616c9975946467e5504be5049d66c02f06e69f1fa19f1587d3de926ba38a89bd085dc9716067df1a6f9c6c0c1ec71395d3eff623bba0c2ec352702f149c7f624f1c7edfc219d6ed0feb4b7c79bda3eba0e46bac2da8e02bc271f3608c1edb0530bd8b298b7473e83be263c047ab04e3aaf1e2ed8c

Testing

Since the command must be executed after building the site, that is, it won’t work with the hugo server.

Firstly, build the site and encrypt the content.

1hugo -b http://localhost:8081 && $HOME/go/bin/encrypt

And then setup a HTTP server to serve the encrypted contents, such as http-server and PHP built-in server.

HTTP Server

To get the http-server by executing npm install --global http-server.

1http-server -p 8081 public

PHP Built-in Server

If you’ve PHP installation on your environment.

1php -S 0.0.0.0:8081 -t public

Deployment

Credit

It’s a fork of Hugo Encrypt, and port it for Hugo modules.