Encrypt Module

The encrypt module allows encrypting or protecting partial contents.

Modulegithub.com/hugomods/encrypt
StatsGitHub 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

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

Import the JS

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.

257dffde6100fc0f-4ef4b3fe536d3fb128bb07a5-050c32b0a54afb9591cc26400afc1b1076314e707849afa70662029c99164ff42df4edd3034bdefc557409a83a1cbf42ab043d9e0e832e4437c81989bb38a1a76de1badb53fdf86c664e3c63df2cc860f971bfa2af2d96514f4f7d373af1d51fd60b9c4fc4c5292469e1324b83bb

Encrypt Markdown Content

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

The following content is protected.

7777b3f91478e806-c5a37d23cbc2abd1ec3d1274-cd9dc921ad5d71d1378552d2994ca312babfb72efd84fc17e9346a212c94308216537df116fe8c89ec623bae350ed9e8d90bcf97fa462b220312ea98863f17d8e587f4f02ef3d99af7a5d5833fab6710d897f8b85855ec297902f9d3e1b2ef6ccb5b6ba4aa344bde8b4682cf2785f206267066dd617c6c4830b8561057d1f734d7f8d8e72dfb

Encrypt Content with Specified Password

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

The following content is protected.

cb7eb7bbe0c35acb-16d0f0cd5ff33e4e1ef5e22d-559b17680a6fe46afc58e9da1c7788c3a8bff1a345efb50ac73738ddacf7a4dc2ea7770e6286ef38f021088dfab9529c6a49015af350b66b0fb785acc148d5f3c3a2f994c1e41a0b114669e1295129a5dd9c62351700b13e4f6a13b17925cdfd3cb1c4f635b2792ba514f6508cf731ccd0e1677b8492e89f5a3e3ffc7948

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.