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.

1495d7dfcd560d15-cd928bee35ccbf5cd97e60b2-b412423002708539e46f4d611ef5d42f0421a008a2db560fa363d4d6e764ceddb6f99ac44241a13a5f9e6bd21cea1167bf5d8138b8239983ab6326988e4c1cfd112fceda0275911cc3d581450a1c7bfc9100bd1a03d313ec1a4c06ade23ed2f0a203288e93840fc443ff63122fde

Encrypt Markdown Content

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

The following content is protected.

b4e69bf245315d76-b773616de1c9fb085b243e4c-86dd6f12e80fa479a4b2eefa4c877e1c7a092eb7a91fff66559bae071d6cf846b4446013365047e0ae796be35ea6b319a39987dc94f16f866632ac8e0c7e523831cf7ec03cc8abb781219e1e2632e0bfcad50e8c4e81cfcdee932514ca67b3e9f0bd76d67538a687c67ded504b4b941efccb2795d61c6eb40903397f32db778853dcecd9254e

Encrypt Content with Specified Password

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

The following content is protected.

8bce35c7b909b17d-231d22a7980c7fd1684f32e4-3c3694c3d68560488aadc72d0bc5327a56c40483b9df24bccc89d89bd1cc2a94554131160233ce08682d59bfc9e61ddbe0d3e831b6fb29f97eb706ac6e39662d07caffd94c604fffc87f7b562d2f1b5708c2688703db1671114e2e94063cf37e7b3fdcfc068ef75c40172c83c6d7036c8b21cd3e1201848282398bc877ab

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.