kopia lustrzana https://github.com/robinmoisson/staticrypt
645 wiersze
24 KiB
HTML
645 wiersze
24 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>StatiCrypt: Password protect static HTML</title>
|
|
<meta name="description" content="">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="stylesheet"
|
|
type="text/css"
|
|
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
|
|
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
|
|
crossorigin="anonymous">
|
|
<style>
|
|
a.no-style {
|
|
color: inherit;
|
|
text-decoration: inherit;
|
|
}
|
|
|
|
body {
|
|
font-size: 16px;
|
|
}
|
|
|
|
label.no-style {
|
|
font-weight: normal;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<h1>
|
|
StatiCrypt
|
|
<div class="pull-right">
|
|
<iframe src="https://ghbtns.com/github-btn.html?user=robinmoisson&repo=staticrypt&type=star&size=large"
|
|
frameborder="0" scrolling="0" width="80px" height="30px"></iframe>
|
|
<iframe src="https://ghbtns.com/github-btn.html?user=robinmoisson&repo=staticrypt&type=fork&size=large"
|
|
frameborder="0" scrolling="0" width="80px" height="30px"></iframe>
|
|
</div>
|
|
<br>
|
|
<small>Password protect a static HTML page</small>
|
|
</h1>
|
|
<p>
|
|
Based on the <a href="https://github.com/brix/crypto-js">crypto-js library</a>, StatiCrypt uses AES-256
|
|
to encrypt your string with your long password in your browser (client side).
|
|
</p>
|
|
<p>
|
|
Download your encrypted string in a HTML page with a password prompt you can upload anywhere (see <a
|
|
target="_blank" href="example/example_encrypted.html">example</a>).
|
|
</p>
|
|
<p>
|
|
The tool is also available as <a href="https://npmjs.com/package/staticrypt">a CLI on NPM</a> and is <a
|
|
href="https://github.com/robinmoisson/staticrypt">open source on GitHub</a>.
|
|
</p>
|
|
<br>
|
|
|
|
<h4>
|
|
<a class="no-style" id="toggle-concept" href="#">
|
|
<span id="toggle-concept-sign">►</span> HOW IT WORKS
|
|
</a>
|
|
</h4>
|
|
<div id="concept" class="hidden">
|
|
<p>
|
|
<b class="text-danger">Disclaimer</b> if you are an at-risk activist, or have extra sensitive
|
|
banking data, you should probably use something else!
|
|
</p>
|
|
<p>
|
|
StatiCrypt generates a static, password protected page that can be decrypted in-browser:
|
|
just send or upload the generated page to a place serving static content (github pages, for example)
|
|
and you're done: the javascript will prompt users for password, decrypt the page and load your HTML.
|
|
</p>
|
|
<p>
|
|
It basically encrypts your page and puts everything with a user-friendly way to use a password
|
|
in the new file. AES-256 is state of the art but <b>brute-force/dictionary attacks would be easy to
|
|
do at a really fast pace: use a long, unusual password!</b>
|
|
<br/> => To be safe, we recommend 16+ alphanum characters, and using a password manager like the
|
|
open-source <a href="http://bitwarden.com">Bitwarden</a>.
|
|
</p>
|
|
<p>
|
|
Feel free to contribute or report any thought to the
|
|
<a href="https://github.com/robinmoisson/staticrypt">GitHub project</a>.
|
|
</p>
|
|
</div>
|
|
<br>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<form id="encrypt_form">
|
|
<div class="form-group">
|
|
<label for="passphrase">Password</label>
|
|
<input type="password" class="form-control" id="passphrase"
|
|
placeholder="Password (choose a long one!)">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="unencrypted_html">HTML/string to encrypt</label>
|
|
<textarea class="form-control"
|
|
id="unencrypted_html"
|
|
placeholder="<html><head>..."
|
|
rows="5"></textarea>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="no-style">
|
|
<input type="checkbox" id="remember" checked>
|
|
Add "Remember me" checkbox (append <code>?staticrypt_logout</code> to your URL to logout)
|
|
<small>
|
|
<abbr class="text-muted"
|
|
title="The password will be stored in clear text in the browser's localStorage upon entry by the user. See "More options" to set the expiration (default: none)">
|
|
(?)
|
|
</abbr>
|
|
</small>
|
|
</label>
|
|
</div>
|
|
|
|
<p>
|
|
<a href="#" id="toggle-extra-option">+ More options</a>
|
|
</p>
|
|
<div id="extra-options" class="hidden">
|
|
<div class="form-group">
|
|
<label for="title">Page title</label>
|
|
<input type="text" class="form-control" id="title" placeholder="Default: 'Protected Page'">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="instructions">Instructions to display the user</label>
|
|
<textarea class="form-control" id="instructions" placeholder="Default: nothing."></textarea>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="passphrase_placeholder">Passphrase input placeholder</label>
|
|
<input type="text" class="form-control" id="passphrase_placeholder"
|
|
placeholder="Default: 'Passphrase'">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="remember_me">"Remember me" checkbox label</label>
|
|
<input type="text" class="form-control" id="remember_me" placeholder="Default: 'Remember me'">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="remember_in_days">"Remember me" expiration in days</label>
|
|
<input type="number"
|
|
class="form-control"
|
|
id="remember_in_days"
|
|
step="any"
|
|
placeholder="Default: 0 (no expiration)">
|
|
<small class="form-text text-muted">
|
|
After this many days, the user will have to enter the passphrase again. Leave empty or set
|
|
to 0 for no expiration.
|
|
</small>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="decrypt_button">Decrypt button label</label>
|
|
<input type="text" class="form-control" id="decrypt_button" placeholder="Default: 'DECRYPT'">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="no-style">
|
|
<input type="checkbox" id="embed-crypto" checked>
|
|
Embed crypto-js into your file
|
|
<small>
|
|
<abbr class="text-muted"
|
|
title="Leave checked to include crypto-js into your file so you can decrypt it offline. Uncheck to load crypto-js from a CDN.">
|
|
(?)
|
|
</abbr>
|
|
</small>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<button class="btn btn-primary pull-right" type="submit">Generate passphrase protected HTML</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row mb-5">
|
|
<div class="col-xs-12">
|
|
<h2>Encrypted HTML</h2>
|
|
<p><a class="btn btn-success download"
|
|
download="encrypted.html"
|
|
id="download-link"
|
|
disabled="disabled">Download html file with password prompt</a></p>
|
|
<pre id="encrypted_html_display">
|
|
Your encrypted string</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!--
|
|
Filename changed to circumvent adblockers that mistake it for a crypto miner (see https://github.com/robinmoisson/staticrypt/issues/107)
|
|
-->
|
|
<script src="lib/kryptojs-3.1.9-1.min.js"></script>
|
|
|
|
<script src="https://cdn.ckeditor.com/4.7.0/standard/ckeditor.js"></script>
|
|
|
|
<script id="cryptoEngine">
|
|
window.cryptoEngine = ((function(){
|
|
const exports = {};
|
|
|
|
/**
|
|
* Salt and encrypt a msg with a password.
|
|
* Inspired by https://github.com/adonespitogo
|
|
*/
|
|
function encrypt(msg, hashedPassphrase) {
|
|
var iv = CryptoJS.lib.WordArray.random(128 / 8);
|
|
|
|
var encrypted = CryptoJS.AES.encrypt(msg, hashedPassphrase, {
|
|
iv: iv,
|
|
padding: CryptoJS.pad.Pkcs7,
|
|
mode: CryptoJS.mode.CBC,
|
|
});
|
|
|
|
// iv will be hex 16 in length (32 characters)
|
|
// we prepend it to the ciphertext for use in decryption
|
|
return iv.toString() + encrypted.toString();
|
|
}
|
|
exports.encrypt = encrypt;
|
|
|
|
/**
|
|
* Decrypt a salted msg using a password.
|
|
* Inspired by https://github.com/adonespitogo
|
|
*
|
|
* @param {string} encryptedMsg
|
|
* @param {string} hashedPassphrase
|
|
* @returns {string}
|
|
*/
|
|
function decrypt(encryptedMsg, hashedPassphrase) {
|
|
var iv = CryptoJS.enc.Hex.parse(encryptedMsg.substr(0, 32));
|
|
var encrypted = encryptedMsg.substring(32);
|
|
|
|
return CryptoJS.AES.decrypt(encrypted, hashedPassphrase, {
|
|
iv: iv,
|
|
padding: CryptoJS.pad.Pkcs7,
|
|
mode: CryptoJS.mode.CBC,
|
|
}).toString(CryptoJS.enc.Utf8);
|
|
}
|
|
exports.decrypt = decrypt;
|
|
|
|
/**
|
|
* Salt and hash the passphrase so it can be stored in localStorage without opening a password reuse vulnerability.
|
|
*
|
|
* @param {string} passphrase
|
|
* @param {string} salt
|
|
* @returns string
|
|
*/
|
|
function hashPassphrase(passphrase, salt) {
|
|
// we hash the passphrase in two steps: first 1k iterations, then we add iterations. This is because we used to use 1k,
|
|
// so for backwards compatibility with remember-me/autodecrypt links, we need to support going from that to more
|
|
// iterations
|
|
var hashedPassphrase = hashLegacyRound(passphrase, salt);
|
|
|
|
return hashSecondRound(hashedPassphrase, salt);
|
|
}
|
|
exports.hashPassphrase = hashPassphrase;
|
|
|
|
/**
|
|
* This hashes the passphrase with 1k iterations. This is a low number, we need this function to support backwards
|
|
* compatibility.
|
|
*
|
|
* @param {string} passphrase
|
|
* @param {string} salt
|
|
* @returns {string}
|
|
*/
|
|
function hashLegacyRound(passphrase, salt) {
|
|
return CryptoJS.PBKDF2(passphrase, salt, {
|
|
keySize: 256 / 32,
|
|
iterations: 1000,
|
|
}).toString();
|
|
}
|
|
exports.hashLegacyRound = hashLegacyRound;
|
|
|
|
/**
|
|
* Add a second round of iterations. This is because we used to use 1k, so for backwards compatibility with
|
|
* remember-me/autodecrypt links, we need to support going from that to more iterations.
|
|
*
|
|
* @param hashedPassphrase
|
|
* @param salt
|
|
* @returns {string}
|
|
*/
|
|
function hashSecondRound(hashedPassphrase, salt) {
|
|
return CryptoJS.PBKDF2(hashedPassphrase, salt, {
|
|
keySize: 256 / 32,
|
|
iterations: 14000,
|
|
hasher: CryptoJS.algo.SHA256,
|
|
}).toString();
|
|
}
|
|
exports.hashSecondRound = hashSecondRound;
|
|
|
|
function generateRandomSalt() {
|
|
return CryptoJS.lib.WordArray.random(128 / 8).toString();
|
|
}
|
|
exports.generateRandomSalt = generateRandomSalt;
|
|
|
|
function getRandomAlphanum() {
|
|
var possibleCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
|
|
var byteArray;
|
|
var parsedInt;
|
|
|
|
// Keep generating new random bytes until we get a value that falls
|
|
// within a range that can be evenly divided by possibleCharacters.length
|
|
do {
|
|
byteArray = CryptoJS.lib.WordArray.random(1);
|
|
// extract the lowest byte to get an int from 0 to 255 (probably unnecessary, since we're only generating 1 byte)
|
|
parsedInt = byteArray.words[0] & 0xff;
|
|
} while (parsedInt >= 256 - (256 % possibleCharacters.length));
|
|
|
|
// Take the modulo of the parsed integer to get a random number between 0 and totalLength - 1
|
|
var randomIndex = parsedInt % possibleCharacters.length;
|
|
|
|
return possibleCharacters[randomIndex];
|
|
}
|
|
|
|
/**
|
|
* Generate a random string of a given length.
|
|
*
|
|
* @param {int} length
|
|
* @returns {string}
|
|
*/
|
|
function generateRandomString(length) {
|
|
var randomString = '';
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
randomString += getRandomAlphanum();
|
|
}
|
|
|
|
return randomString;
|
|
}
|
|
exports.generateRandomString = generateRandomString;
|
|
|
|
function signMessage(hashedPassphrase, message) {
|
|
return CryptoJS.HmacSHA256(
|
|
message,
|
|
CryptoJS.SHA256(hashedPassphrase).toString()
|
|
).toString();
|
|
}
|
|
exports.signMessage = signMessage;
|
|
|
|
return exports;
|
|
})())
|
|
</script>
|
|
|
|
<script id="codec">
|
|
window.codec = ((function(){
|
|
const exports = {};
|
|
/**
|
|
* Initialize the codec with the provided cryptoEngine - this return functions to encode and decode messages.
|
|
*
|
|
* @param cryptoEngine - the engine to use for encryption / decryption
|
|
*/
|
|
function init(cryptoEngine) {
|
|
// TODO: remove on next major version bump. This is a hack to make the salt available in all functions here in a
|
|
// backward compatible way (not requiring to change the password_template).
|
|
const backwardCompatibleSalt = '##SALT##';
|
|
|
|
const exports = {};
|
|
|
|
/**
|
|
* Top-level function for encoding a message.
|
|
* Includes password hashing, encryption, and signing.
|
|
*
|
|
* @param {string} msg
|
|
* @param {string} password
|
|
* @param {string} salt
|
|
* @param {boolean} isLegacy - whether to use the legacy hashing algorithm (1k iterations) or not
|
|
*
|
|
* @returns {string} The encoded text
|
|
*/
|
|
function encode(msg, password, salt, isLegacy = false) {
|
|
// TODO: remove in the next major version bump. This is to not break backwards compatibility with the old way of hashing
|
|
const hashedPassphrase = isLegacy
|
|
? cryptoEngine.hashLegacyRound(password, salt)
|
|
: cryptoEngine.hashPassphrase(password, salt);
|
|
const encrypted = cryptoEngine.encrypt(msg, hashedPassphrase);
|
|
// we use the hashed password in the HMAC because this is effectively what will be used a password (so we can store
|
|
// it in localStorage safely, we don't use the clear text password)
|
|
const hmac = cryptoEngine.signMessage(hashedPassphrase, encrypted);
|
|
|
|
return hmac + encrypted;
|
|
}
|
|
exports.encode = encode;
|
|
|
|
/**
|
|
* Top-level function for decoding a message.
|
|
* Includes signature check and decryption.
|
|
*
|
|
* @param {string} signedMsg
|
|
* @param {string} hashedPassphrase
|
|
* @param {string} backwardCompatibleHashedPassword
|
|
*
|
|
* @returns {Object} {success: true, decoded: string} | {success: false, message: string}
|
|
*/
|
|
function decode(signedMsg, hashedPassphrase, backwardCompatibleHashedPassword = '') {
|
|
const encryptedHMAC = signedMsg.substring(0, 64);
|
|
const encryptedMsg = signedMsg.substring(64);
|
|
const decryptedHMAC = cryptoEngine.signMessage(hashedPassphrase, encryptedMsg);
|
|
|
|
if (decryptedHMAC !== encryptedHMAC) {
|
|
// TODO: remove in next major version bump. This is to not break backwards compatibility with the old 1k
|
|
// iterations in PBKDF2 - if the key we try isn't working, it might be because it's a remember-me/autodecrypt
|
|
// link key, generated with 1k iterations. Try again with the updated iteration count.
|
|
if (!backwardCompatibleHashedPassword) {
|
|
return decode(
|
|
signedMsg,
|
|
cryptoEngine.hashSecondRound(hashedPassphrase, backwardCompatibleSalt),
|
|
hashedPassphrase
|
|
);
|
|
}
|
|
|
|
return { success: false, message: "Signature mismatch" };
|
|
}
|
|
|
|
// TODO: remove in next major version bump. If we're trying to double hash for backward compatibility reasons,
|
|
// and the attempt is successful, we check if we should update the stored password in localStorage. This avoids
|
|
// having to compute the upgrade each time.
|
|
if (backwardCompatibleHashedPassword) {
|
|
if (window && window.localStorage) {
|
|
const storedPassword = window.localStorage.getItem('staticrypt_passphrase');
|
|
|
|
// check the stored password is actually the backward compatible one, so we don't save the new one and trigger
|
|
// the "remember-me" by mistake, leaking the password
|
|
if (storedPassword === backwardCompatibleHashedPassword) {
|
|
window.localStorage.setItem('staticrypt_passphrase', hashedPassphrase);
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
decoded: cryptoEngine.decrypt(encryptedMsg, hashedPassphrase),
|
|
};
|
|
}
|
|
exports.decode = decode;
|
|
|
|
return exports;
|
|
}
|
|
exports.init = init;
|
|
|
|
return exports;
|
|
})())
|
|
</script>
|
|
|
|
<script id="formater">
|
|
window.formater = ((function(){
|
|
const exports = {};
|
|
/**
|
|
* Replace the placeholder tags (between '{tag}') in the template string with provided data.
|
|
*
|
|
* @param {string} templateString
|
|
* @param {Object} data
|
|
*
|
|
* @returns string
|
|
*/
|
|
function renderTemplate(templateString, data) {
|
|
return templateString.replace(/{\s*(\w+)\s*}/g, function (_, key) {
|
|
if (data && data[key] !== undefined) {
|
|
return data[key];
|
|
}
|
|
|
|
return "";
|
|
});
|
|
}
|
|
exports.renderTemplate = renderTemplate;
|
|
|
|
|
|
return exports;
|
|
})())
|
|
</script>
|
|
|
|
<script>
|
|
var encode = codec.init(cryptoEngine).encode;
|
|
|
|
// enable CKEDIRTOR
|
|
CKEDITOR.replace('instructions');
|
|
|
|
var htmlToDownload;
|
|
|
|
/**
|
|
* Extract js code from <script> tag and return it as a string
|
|
*
|
|
* @param id
|
|
* @returns
|
|
*/
|
|
var getScriptAsString = function (id) {
|
|
return document.getElementById(id)
|
|
.innerText.replace(/window\.\w+ = /, '');
|
|
}
|
|
|
|
/**
|
|
* Register something happened - this uses a simple Supabase function to implement a counter, and allows use to drop
|
|
* google analytics.
|
|
*
|
|
* @param action
|
|
*/
|
|
function trackEvent(action) {
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open('POST', 'https://zlgpaemmniviswibzuwt.supabase.co/rest/v1/rpc/increment_analytics', true);
|
|
xhr.setRequestHeader('Content-type', 'application/json; charset=UTF-8')
|
|
xhr.setRequestHeader('apikey', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InpsZ3BhZW1tbml2aXN3aWJ6dXd0Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NjkxMjM0OTcsImV4cCI6MTk4NDY5OTQ5N30.wNoVDHG7F6INx-IPotMs3fL1nudfaF2qvQDgG-1PhNI')
|
|
xhr.setRequestHeader('Authorization', 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InpsZ3BhZW1tbml2aXN3aWJ6dXd0Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NjkxMjM0OTcsImV4cCI6MTk4NDY5OTQ5N30.wNoVDHG7F6INx-IPotMs3fL1nudfaF2qvQDgG-1PhNI')
|
|
xhr.send(
|
|
JSON.stringify({
|
|
action_input: action
|
|
}
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Fill the password prompt template with data provided.
|
|
* @param data
|
|
*/
|
|
var setFileToDownload = function (data) {
|
|
var request = new XMLHttpRequest();
|
|
request.open('GET', 'lib/password_template.html', true);
|
|
request.onload = function () {
|
|
var renderedTmpl = formater.renderTemplate(request.responseText, data);
|
|
|
|
var downloadLink = document.querySelector('a.download');
|
|
downloadLink.href = 'data:text/html,' + encodeURIComponent(renderedTmpl);
|
|
downloadLink.removeAttribute('disabled');
|
|
|
|
htmlToDownload = renderedTmpl;
|
|
};
|
|
request.send();
|
|
};
|
|
|
|
/**
|
|
* Download crypto-js lib to embed it in the generated file, update the file when done.
|
|
* @param data
|
|
*/
|
|
var setFileToDownloadWithEmbeddedCrypto = function (data) {
|
|
var request = new XMLHttpRequest();
|
|
request.open('GET', 'lib/kryptojs-3.1.9-1.min.js', true);
|
|
request.onload = function () {
|
|
data['crypto_tag'] = '<script>' + request.responseText + '</scr' + 'ipt>';
|
|
setFileToDownload(data);
|
|
};
|
|
request.send();
|
|
};
|
|
|
|
// register page load
|
|
window.onload = function () {
|
|
trackEvent('show_index');
|
|
};
|
|
|
|
/**
|
|
* Handle form submission.
|
|
*/
|
|
document.getElementById('encrypt_form').addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
|
|
trackEvent('generate_encrypted');
|
|
|
|
// update instruction textarea value with CKEDITOR content
|
|
// (see https://stackoverflow.com/questions/3147670/ckeditor-update-textarea)
|
|
CKEDITOR.instances['instructions'].updateElement();
|
|
|
|
var unencrypted = document.getElementById('unencrypted_html').value,
|
|
passphrase = document.getElementById('passphrase').value;
|
|
|
|
var salt = cryptoEngine.generateRandomSalt();
|
|
var encryptedMsg = encode(unencrypted, passphrase, salt);
|
|
|
|
var decryptButton = document.getElementById('decrypt_button').value,
|
|
instructions = document.getElementById('instructions').value,
|
|
isRememberEnabled = document.getElementById('remember').checked,
|
|
pageTitle = document.getElementById('title').value.trim(),
|
|
passphrasePlaceholder = document.getElementById('passphrase_placeholder').value.trim(),
|
|
rememberDurationInDays = document.getElementById('remember_in_days').value || 0,
|
|
rememberMe = document.getElementById('remember_me').value;
|
|
|
|
var data = {
|
|
crypto_tag: '<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js" integrity="sha384-lp4k1VRKPU9eBnPePjnJ9M2RF3i7PC30gXs70+elCVfgwLwx1tv5+ctxdtwxqZa7" crossorigin="anonymous"></scr' + 'ipt>',
|
|
decrypt_button: decryptButton ? decryptButton : 'DECRYPT',
|
|
encrypted: encryptedMsg,
|
|
instructions: instructions ? instructions : '',
|
|
is_remember_enabled: isRememberEnabled ? 'true' : 'false',
|
|
js_codec: getScriptAsString('codec'),
|
|
js_crypto_engine: getScriptAsString('cryptoEngine'),
|
|
passphrase_placeholder: passphrasePlaceholder ? passphrasePlaceholder : 'Passphrase',
|
|
remember_duration_in_days: rememberDurationInDays.toString(),
|
|
remember_me: rememberMe ? rememberMe : 'Remember me',
|
|
salt: salt,
|
|
title: pageTitle ? pageTitle : 'Protected Page',
|
|
};
|
|
|
|
document.getElementById('encrypted_html_display').textContent = encryptedMsg;
|
|
|
|
if (document.getElementById("embed-crypto").checked) {
|
|
setFileToDownloadWithEmbeddedCrypto(data);
|
|
} else {
|
|
setFileToDownload(data);
|
|
}
|
|
});
|
|
|
|
document.getElementById('toggle-extra-option')
|
|
.addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
document.getElementById('extra-options').classList.toggle('hidden');
|
|
});
|
|
|
|
var isConceptShown = false;
|
|
document.getElementById('toggle-concept')
|
|
.addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
|
|
isConceptShown = !isConceptShown;
|
|
|
|
document.getElementById('toggle-concept-sign').innerText = isConceptShown ? '▼' : '►';
|
|
|
|
document.getElementById('concept').classList.toggle('hidden');
|
|
});
|
|
|
|
|
|
/**
|
|
* Browser specific download code.
|
|
*/
|
|
document.getElementById('download-link')
|
|
.addEventListener('click', function (e) {
|
|
// only register the click event if there is actually a generated file
|
|
if (htmlToDownload) {
|
|
trackEvent('download_encrypted');
|
|
}
|
|
|
|
var isIE = (navigator.userAgent.indexOf("MSIE") !== -1) || (!!document.documentMode === true); // >= 10
|
|
var isEdge = navigator.userAgent.indexOf("Edge") !== -1;
|
|
|
|
// download with MS specific feature
|
|
if (htmlToDownload && (isIE || isEdge)) {
|
|
e.preventDefault();
|
|
var blobObject = new Blob([htmlToDownload]);
|
|
window.navigator.msSaveOrOpenBlob(blobObject, 'encrypted.html');
|
|
}
|
|
|
|
return true;
|
|
})
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|