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.

58f2559c72fe3036-a2d39a503785b4059ae0e9ae-803621844aec0a814a5096e1d7841202a48a7c5348d3148babe1547dc2afe80138d843fcd405f0ca6362b6cd75389c2e52aad3ec32bbb0b5b78e3ef07999e5d8f588afb0994d162f33a278d1f824504b0af4bf00e13c82a7f9fda1ff5525ec50d18e84fbd1e99f43347aced3cb8f

Encrypt Markdown Content

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

The following content is protected.

cb54e6f30a330942-3de443f30541736b79363708-0615b480e752c2b7eba1da8ff538a2024856c574adcc96f9f682b6974e743a0dc3e4f0a59be2a0dba3da1d27d3da3f304a6182e628f71ca18c297891b32a738041717a46595c04f5326dcd1e5cdb83f822d51172f2dd65acc025cd998b4c645f658a7798f1b72ce9941e7c49edaaf3d8783b0ac0f5751fed7606d890ca3becd0ff5495669463

Encrypt Content with Specified Password

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

The following content is protected.

ddb7cb5e53e1937c-d6d15340efcadff9b16c8809-18604bbb39fc1fdd672b95410a21813b06a77d23fcf33430131cb56e963d10ff33a8effa6f5f6af70d416030722899e17473d1401b073a4380e7ce27deb1e90d30438d28f0288d84a3b5219f035f9942f0da68874317c3968ec8f64daae1bbb45461e370c1626dcfc2fe1a0d9a5019a11315afeeba59a0b98313a23280cf

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.