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.

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.

a6ac3662153e6719-01e485bbd859b3c4d40d887c-17778f24a68711c315326cffdac58690729c41083c5c290c2adfe7ee5af4aacccba112b974c8de1a8f93a5ae483cfd1e5850ca8263f0b9fc378b8c5886c9782d59bdaebb1eb551b991bddeb01e73e448c9628fe7bb0b1a54d0e710d6a475389a6e14b38ba74257d82fc08d0cefc2

Encrypt Markdown Content§

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

The following content is protected.

36f3f828093a53eb-b1de5fc34361f021f14856ac-499da693e5ab565f79e02b514e68751213e45cf7c280d7f6d8ab56e92c809234bf14180da3faa57ba187618bdb6d1737efac44dfc202ee04d233f51eb2e75a323810ba37efbad9d744d45185995f354cba06f7f875d1369c58c30e4c8438a61c26adffacbe4ab5d98cf80714a309521f6b1d8ad0c5c317653706cb1032ba255b01c9befe7784

Encrypt Content with Specified Password§

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

The following content is protected.

ca8a6b3db41356e9-4aac6b23fda78cca247e3cac-c89cb0fbc724990081caf14cb2f7e1962e51d0aa96a71c22761cf45a2c86c18d03f6de63175efc023d2b0a8b9d435c1c27ed082924bed0cb021f6ee80a852273e1d4461698abe84ccd635106a449f59742c9e927b406d178cddf3f3b68f68b28414dd50e7cc704917d83ca512bf0b6d96378e56b7fc86ad9ff750c6f2032

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.