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.

4ca76ddaffa4b06c-159b74b952b0e2fc52607db6-6490a9a40d52af14479342f529a2677b46a8c68a1a1e9b022483292e91136b98ebb1d88a133b3938756fa10a81757da8f9050531eff5b7d0aa83eaf3ab857731a8e07f44ca0d4c19edcb35154c31c7921efa36d60e137c56ca1a6a073869336a642cb8101c0ac2082d55be31c0a8

Encrypt Markdown Content

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

The following content is protected.

495e83c82860e014-ec9ec71bd4a704ab083e98cc-26f439c5e015bc9d1ced4a52daff44da8de7ebf8b8a29b782985984dce2d2e3c98e4dcbfd4a73c80cd74f15c7d3ebcc7308aaf6b730c5543be3606d05d17b2b5969f1e446acd31a7a41951bd171eb2c08af022d195894a8cb5332ff1050def392d2fa484c6869e23e4115420f7846874b1fd0dffb82e2772c83d126cdf92630e7cda6db5bb62

Encrypt Content with Specified Password

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

The following content is protected.

3065ff26aecee2c7-4228f2b6afd583d162f6f559-8faad3b42be67aa353e43eed44fcfd1727fab23c4e2597c21d40499e2ccbbf6e0f9119b8fa0672aa7d734efa7c9503806119ed9409d01183e7d386114804bd466403b9d8d24fd294fe62a939ef8479d0f165adbad02bb26742a34995e5f6484736473933a8af062d361a76ffa0eeb56e2017fdbd519fb31a1d896e3e56da

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.