StatiCrypt uses AES-256 to encrypt your HTML file with your passphrase and return a static page including a password prompt and the javascript decryption logic that you can safely upload anywhere (see what the page looks like).
This means you can password protect the content of your public static HTML file, without any back-end – serving it over Netlify, GitHub pages, etc. (see the detail of how it works).
You can encrypt a file online in your browser (client side) at https://robinmoisson.github.io/staticrypt, or use the CLI to do it in your build process.
CLI
Installation
Staticrypt is available through npm as a CLI, install with
You can then run it with npx staticrypt ...
. You can also install globally with npm install -g staticrypt
and then just call staticrypt ...
.
Examples
These will create a
.staticrypt.json
file in the current directory, see the FAQ as to why. You can prevent it by setting the--config
flag to “false”.
Encrypt a file: Encrypt test.html
and create a test_encrypted.html
file (add -o my_encrypted_file.html
to change the name of the output file):
staticrypt test.html MY_PASSPHRASE
Encrypt a file with the passphrase in an environment variable: set your passphrase in the STATICRYPT_PASSWORD
environment variable (.env
files are supported):
# the passphrase is in the STATICRYPT_PASSWORD env variable
staticrypt test.html
Encrypt a file and get a shareable link containing the hashed password – you can include your file URL or leave blank:
{}
will be replaced with each file name by the find
command – if you wanted to move the encrypted files to an encrypted/
directory, you could use -o encrypted/{}
):
find . -type f -name "*.html" -exec staticrypt {} MY_PASSPHRASE -o {} ;
Encrypt all html files in a directory except the ones ending in _encrypted.html
:
find . -type f -name "*.html" -not -name "*_encrypted.html" -exec staticrypt {} MY_PASSPHRASE ;
CLI Reference
The passphrase argument is optional if STATICRYPT_PASSWORD
is set in the environment or .env
file.
HOW STATICRYPT WORKS
So, how can you password protect html without a back-end?