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.

a2a99dea626293d2-433f1989043629106abd8d65-f43f74dd153f16deaeeb6596471d244ddb50a1fb872a29d40938b0b7ecb54e6153a2b240cb1ebd73ef744bf767618a3954fadf85f6f7910a78895b00e7149506084effeaebf1aca4387429cfbca8956d1f3f1a3821b8f9d0be2625f4c397a85deb31216233b4cb2d4f727ab38b26

Encrypt Markdown Content

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

The following content is protected.

13f4055c9d00aa37-1861c6cfb67ae7136eb11f38-770de2fae7253515b90d49f408f7ad98312d6697e2892de70df0102dddb76ee2c29015bcd29f58063bfadca8cf7a0dcfb1b8ca0d5e801ba02d16e00d8c2ed79f9ce77c03dec66247d2f13b090d30e4a95febabec1b7a598f25d5f3281880cc86aaa76f50ea75724a03d2dbff5adcc973d0d182e40fcf4e6c4709f4773ad1b0d3f1c2d0f7b535

Encrypt Content with Specified Password

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

The following content is protected.

bf6c97a89b4cb823-1290a128944e2a2fea6f65c1-33ebfb1ee9a15405a0bce1edac3afe4b784876ccb9f6d305e4885d1ff67d215535aefb99b6a291d28c49f637d3e60d5cd30b7ddb958b48e816510f25cc027ddc6d5675d07dfe326230a4e0e1fba42e99b0f1277dd1591b450e129d144d7b07a6fa72c7f753687b574aa6ba7a7156cd32f4b8b8491baa85d5ff9711e936e4

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.