Generate a standalone HTML page that decrypts data.
Generate a standalone HTML page that decrypts an encrypted message. Used by html-vault
.
The idea is to have a tool that encrypts any message/secret and generates something that can decrypt itself. I see two advantages of the HTML-based solution over others:
With self-decrypting-html-page
, you can use this functionality anywhere. Consider the examples below.
There are three ways to install this tool:
npm install -g self-decrypting-html-page
npx self-decrypting-html-page
# basic usage
echo 'my secret message' | npx self-decrypting-html-page >encrypted-message.html
# This is your key:
# 964d87e28a7f468afe33c255e689d2baa5d67dabc43d6262971a5efd18917929
# write decryption key to file
echo 'my secret message' | npx self-decrypting-html-page >encrypted-message.html 2>key.txt
cat key.txt
# 964d87e28a7f468afe33c255e689d2baa5d67dabc43d6262971a5efd18917929
npm i self-decrypting-html-page
const encryption = require('sodium-encryption')
const generateHTML = require('self-decrypting-html-page')
const msg = Buffer.from('super secret message')
const key = encryption.key()
console.log('key:', key.toString('hex'))
const nonce = encryption.nonce()
const encrypted = encryption.encrypt(msg, nonce, key)
const html = generateHTML(nonce, encrypted)
// write this HTML to a file, open in the browser
Write the template for self-decrypting HTML page. Check decrypt.html
for the necessary elements.
Generating a custom self-decrypting HTML page from the command line:
echo 'my secret message' | npx self-decrypting-html-page --html path/to/template.html >encrypted-message.html
Generating a it using JS:
const {readFileSync} = require('fs')
const {join} = require('path')
const generateHTML = require('self-decrypting-html-page/custom-html')
const template = readFileSync(join(__dirname, 'template.html'))
const html = generateHTML(nonce, encrypted, template)
lib/decrypt.js
contains the logic to decrypt the message, using the nonce and the password entered by the user.lib/decrypt.js
gets bundled with all its dependencies and stored in decrypt.js
, using Browserify.generate.js
. The version of self-decrypting-html-page
published to npm already contains it.generateHTML(nonce, encrypted)
or run it from the command line, it will replace placeholders in the HTML (that already contains the code to decrypt) and give the final string back to you.If you have a question, found a bug or want to propose a feature, have a look at the issues page.