Skip to content

Instantly share code, notes, and snippets.

@bleonard252
Created September 21, 2018 23:29
Show Gist options
  • Save bleonard252/ed836cd11e029bd3f1195093e289d288 to your computer and use it in GitHub Desktop.
Save bleonard252/ed836cd11e029bd3f1195093e289d288 to your computer and use it in GitHub Desktop.
SJCL Multipage Encrypt (Doubtmode)

Doubtmode

"Doubtmode" is my name for a method of page encryption based on the Stanford Javascript Crypto Library, also known as SJCL. You can configure it however you want, but it must have a password to decrypt it.

How to use (Single page)

To start, just slip the following into the <head> anywhere (it doesn't matter):

<script src='https://bitwiseshiftleft.github.io/sjcl/sjcl.js'></script>

Then, pop open the browser console with that script and execute the doubt_encode() function from doubtmode.js, filling in the arguments. For example:

sjcl_encrypt("PASSword1234", "Page data")

As long as you use your browser console, it should be fine. Don't store your logs where others can see them. The above command should output something like the below:

{"iv":"fGJasLSI+R7UnBZfazf79Q==","v":1,"iter":10000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"E9EIJnTbF7g=","ct":"SoM5vTg1B/i0dV489w=="}

Keep it in this form. In a "submit" function or in a <script> tag, add the following code (changing the variable name is OK).

pagedata = 'that code from above: USE SINGLE QUOTES!';
document.close(); //this is so that the next function overwrites the whole page, rewrite as you see fit
document.write(sjcl_decrypt("PASSword1234", pagedata));

As long as the data is intact and correct, it should immediately overwrite the contents of the page. (Remove the comment when one-lining it.)

How to use (Multipage)

Let's go back. Let's use a different code snippet. This CodePen will get the value of a drop-down selection: https://codepen.io/bleonard252/pen/WgmWLb .

Use that value alongside this:

var elementes = {
  "Option1": '{"iv":"fGJasLSI+R7UnBZfazf79Q==","v":1,"iter":10000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"E9EIJnTbF7g=","ct":"SoM5vTg1B/i0dV489w=="}',
  "Option2": '{"iv":"fGJasLSI+R7UnBZfazf79Q==","v":1,"iter":10000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"E9EIJnTbF7g=","ct":"SoM5vTg1B/i0dV489w=="}',
  "Option3": '{"iv":"fGJasLSI+R7UnBZfazf79Q==","v":1,"iter":10000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"E9EIJnTbF7g=","ct":"SoM5vTg1B/i0dV489w=="}'

}
var rr = document.getElementById("note");
sjcl_decrypt("PASSword12345", elementes[rr.value]);

Each value in the Elementes variable is an encrypted page. (They should be different, but I'm lazy.) You can, of course, rename all the variables, but not the functions.

PROTIP: Use the Option value attribute, as below, to get better internal names:

<option value="Option1">Option 1</option>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment