Wondering what’s next for npm?Check out our public roadmap! »


    2.0.5 • Public • Published


    Generate a standalone HTML page that decrypts an encrypted message. Used by html-vault.

    npm version build status ISC-licensed support me via GitHub Sponsors chat with me on Twitter

    The idea is two 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:

    • low entry-barrier: Everyone has a web browser. Everyone with a reasonably modern browser will be able to use the tool, without installing anything. It is also more platform-independent than other solutions.
    • self-contained: The generated page has all the logic built-in that it needs to decrypt the encrypted message. It can be stored as a standalone file.

    With self-decrypting-html-page, you can use this functionality anywhere. Consider the examples below.

    Usage from the command line

    There are three ways to install this tool:

    • standalone binaries from the releases page
    • installing globally using npm: npm install -g self-decrypting-html-page
    • temporarily installing it into a temp directory and running it, using npx: 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

    Usage with JS

    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

    Usage with custom HTML template

    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)

    How it works


    If you have a question, found a bug or want to propose a feature, have a look at the issues page.


    npm i self-decrypting-html-page

    DownloadsWeekly Downloads






    Unpacked Size

    130 kB

    Total Files


    Last publish


    • avatar