Skip to content

Instantly share code, notes, and snippets.

@getjump
Created May 17, 2018 00:39
Show Gist options
  • Select an option

  • Save getjump/3f8a7765530bd1e1d6017239aeb2bc50 to your computer and use it in GitHub Desktop.

Select an option

Save getjump/3f8a7765530bd1e1d6017239aeb2bc50 to your computer and use it in GitHub Desktop.
{% if page.encrypted %}
{% asset jsencrypt.js %}
<script>
var storedEncrypted = '';
function decrypt() {
var key = window.location.hash.substr(1);
var text = storedEncrypted;
var keyArray = sha256.update(key + _gj.salt).array();
var iv = aesjs.utils.hex.toBytes(_gj.iv);
var encryptedBytes = aesjs.utils.hex.toBytes(text);
var aesCbc = new aesjs.ModeOfOperation.cbc(keyArray, iv);
var decryptedBytes = aesCbc.decrypt(encryptedBytes);
$('#encrypted').html(aesjs.utils.utf8.fromBytes(decryptedBytes));
}
$('document').ready(function () {
storedEncrypted = $('#encrypted').text().trim();
if (window.location.hash == '') {
return;
}
decrypt();
});
$(window).bind('hashchange', function () {
if (window.location.hash == '') {
return;
}
decrypt();
});
</script>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment