Sidejar
Docs menu

Encryption

Light encryption keeps content out of View Source, copy-paste and search engines. It is not strong protection: the key is in your page, so a determined person can decrypt it. It's meant to stop casual cheating.

Encrypt in any of these places (it's the same code everywhere):

  • The decrypt content tool, in your browser: write the intro and the rest, and copy the finished block with the rest already encrypted. Nothing is sent anywhere. Best for static sites. (The encrypt tool does just the encryption.)
  • Your server or build step, with sidejar-crypto.js (1.5 KB, no browser code; Node 18+, Workers, Deno, Bun). Download it from https://cdn.sidejar.com/v1/sidejar-crypto.js into your project, then:
import { encrypt } from "./sidejar-crypto.js";

const html = `<template>${await encrypt("<p>Members only</p>", "my-key")}</template>`;

Decrypt in onpaid, one of three ways:

<!-- 1. No key: content encrypted with the default key -->
<sidejar-content for="tip" onpaid="Sidejar.decrypt">…</sidejar-content>

<!-- 2. A key on the element -->
<sidejar-content for="tip" onpaid="Sidejar.decrypt" data-key="my-key">…</sidejar-content>

<!-- 3. Your own function that passes the key -->
<script>
  function myDecrypt(content) {
    return Sidejar.decrypt(content, "my-key");
  }
</script>
<sidejar-content for="tip" onpaid="myDecrypt">…</sidejar-content>

A wrong key keeps the content locked and fires content_handler_failed.

A readable opening: make it the intro. It's in the page as normal text, as is or fading out, and only the rest is encrypted. See the demos.