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.

d1e2dda7bbb0a272-e2efb219f1de0d2b200cc805-1166dd770506c28dfa6e73f06d7ecd44ee6fa01e569ae748f19598f13fc6cd389776774bc25d15816355d7aa9f9f9b9bdc05e085ed012905016d36dbf264550867cb26c67dd93cc6694efc23d0f6f6c59422080d0e3d247e3e95e2b203e1623134ed40736957b614c14c70ff7c5f

Encrypt Markdown Content

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

The following content is protected.

355b31456dc8921e-03744d0d481f3cb00b4aef8f-5cacd1be8e13b1be31e7309125b148ae14309913b459df5063a84a8e0a99d5131d45a7bb9d850a12acd129deb9f4804423ec19fa2001cbf396c3c845a40f5e5c018c39333139be389718f378f0ce1881af3c43c2dcd4fb06e67a477512f4d69b27ee1a7aff3cc6892e06d09b1a85e3409b107839aa3ba3fdacdfd5023d93be0e9c576912bd61

Encrypt Content with Specified Password

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

The following content is protected.

0781a3cfd354c379-0722614966e77a99df644322-bbeca5a0455f56d700cd116821bc41714c1b99912fe84914448733c687faa311d0c99f2ac70a1f858483413ef987a12a323f3286e648e2671741078d24461952110689531dd843f32409bcd526219ccc2d6cdc175c5458d67fb602d2995112f6945c495b76b6218ac76e71b9b79a942845b6e42c75e3800c15519e5d67e4

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.