Socket
Socket
Sign inDemoInstall

pagecrypt

Package Overview
Dependencies
3
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pagecrypt

Easily add client-side password-protection to your Single Page Applications and HTML files.


Version published
Weekly downloads
833
decreased by-16.45%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

4.0.0 - 2021-04-29

Major UX and performance improvements!

This version uses document.write() to show the encrypted payload instead of using an <iframe> like pagecrypt < v4 did. Since this means browsers won't have to create a separate DOM instance, this brings good performance improvements.

Features

  • feature(UX): Major UX improvement - save CryptoKey to sessionStorage to gain massive UX + performance improvement on repeat visits.
  • feature(UX): Show results faster by removing the <iframe> and show content directly in the top-level document instead.
  • feature(DX): By removing the <iframe>, we also now allow embedded apps and webpages to use the full top-level document. Unlocks many new possible features that wouldn't work in pagecrypt < v4.
  • feature(UX): Show a loading state when loading large encrypted payloads.
  • feature(UX): Show loading spinner when decrypting for better UX.
  • feature(UX): Improve perceived loading performance by not blocking the main thread on page load.
    • This was achieved in part by the loading state, but also by moving the encrypted payload from a render-blocking inline <script> into a <pre> that only contains the raw data.
    • This way, the browser can do more work in parallel, which speeds up the initial page load.
  • feature(UX): Remove the success message and 1s timeout after successful decryption to improved perceived loading performance.
  • feature(build): Improve code transformations applied at build time to optimize decrypt-template.html
  • feature(UX): Add autofocus to password input when pageload has completed.

Fixes

  • fix(build): Remove old iframe solution that's no longer relevant
  • fix(docs): Fix invalid docstring for encryptHTML()

Readme

Source

🔐 PageCrypt - Password Protected Single Page Applications and HTML files

Easily add client-side password-protection to your Single Page Applications and HTML files.

Inspired by MaxLaumeister/PageCrypt, but rewritten to use native Web Crypto API and greatly improve UX + security. Thanks for sharing an excellent starting point to create this tool!

Get started

There are 3 different ways to use pagecrypt:

1. CLI

Encrypt a single HTML-file with one command:

npx pagecrypt <src> <dest> [password] [options]

Encrypt using a generate password with given length:

npx pagecrypt <src> <dest> -g <length>
1.1. CLI Help
  Description
    Encrypt the <src> HTML file with [password] and save the result in the <dest> HTML file.

  Usage
    $ pagecrypt <src> <dest> [password] [options]

  Options
    -g, --generate-password    Generate a random password with given length. Must be a number if used.
    -v, --version              Displays current version
    -h, --help                 Displays this message

  Examples
    $ pagecrypt index.html encrypted.html password
    $ pagecrypt index.html encrypted.html --generate-password 64
    $ pagecrypt index.html encrypted.html -g 64

2. Automate pagecrypt in your build process

This allows automated encrypted builds for single page applications

npm i -D pagecrypt

package.json:

{
    "devDependencies": {
        "pagecrypt": "^3.0.0"
    },
    "scripts": {
        "build": "...",
        "postbuild": "pagecrypt index.html encrypted.html password"
    }
}

3. Node.js API

You can also use pagecrypt in your Node.js scripts:

encrypt(inputFile: string, outputFile: string, password: string): Promise<void>
import { encrypt } from 'pagecrypt'

// Encrypt a HTML file and write to the filesystem
await encrypt('index.html', 'encrypted.html', 'password')
encryptHTML(inputHTML: string, password: string): Promise<string>
import { encryptHTML } from 'pagecrypt'

// Encrypt a HTML string and return an encrypted HTML string.
// Write it to a file or send as an HTTPS response.
const encryptedHTML = await encryptHTML(
    `<!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="UTF-8">
        </head>
        <body>
            Secret
        </body>
    </html>
`,
    'password',
)
generatePassword(length: number): string
import { generatePassword, encrypt, encryptHTML } from 'pagecrypt'

// Generate a random password without any external dependencies
const pass = generatePassword(64)

// Works with both JS API:s
await encrypt('index.html', 'encrypted.html', pass)
const encryptedHTML = await encryptHTML('html string', pass)

Development

The project consists of four parts:

  • /web - Web frontend for public webpage (decrypt-template.html). Built using Vite & Tailwind CSS.
  • /index.js - pagecrypt main library.
  • /cli.js - pagecrypt CLI.
  • /test - testing setup

Setup a local development environment

  1. Install Node.js >= 15.0.0
  2. Run npm install in project root.
  3. Install and use mkcert to generate local certificates to enable HTTPS for the development server. For example mkcert localhost 192.168.1.32 to generate a two files ending with *.pem.
  4. Update vite.config.js to load the generated *.pem files in the https section.
  5. To use npm run serve, also update to the correct *.pem filenames in the npm script.

Testing

npm test will run basic tests for JS API and CLI. Verify test results by opening the test/out-*.html files in your browser.


Welcome to submit your pull requests!

Keywords

FAQs

Last updated on 29 Apr 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc