-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathencrypt.js
62 lines (60 loc) · 2.12 KB
/
encrypt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var myDropzone = new FileDropzone({
target: '#box',
fileHoverClass: 'entered',
clickable: true,
multiple: false,
forceReplace: true,
accept: 'text/html',
onChange: function () {
var files = this.getFiles()
var elem = this.element.find('.files')
elem.empty()
files.forEach(function (item) {
elem.append('<div class="file-name" data-id="' + item.id + '">' + item.name + '</div>')
})
}
});
var decHtmlP1 = "<!DOCTYPE html>\n" +
"<html lang=\"en\">\n" +
"<head>\n" +
" <meta charset=\"UTF-8\">\n" +
" <title>Decrypt</title>\n" +
" <script>" + cryptoJSsrc + "</script>\n" +
"</head>\n" +
"<body>\n" +
"<h3>Decrypt Webpage</h3>\n" +
"<form action=\"javascript:void(9)\" onsubmit=\"decrypt()\">\n" +
" <label for=\"password\">Password: </label>\n" +
" <input type=\"password\" id=\"password\" autocomplete=\"off\">\n" +
" <input type=\"submit\" value=\"Decrypt\">\n" +
"</form>\n" +
"<script>\n" +
" var base64Encrypted=\"";
var decHtmlP2 = "\";\n" +
" function decrypt() {\n" +
" try {\n" +
" var password = document.getElementById('password').value;\n" +
" var html = CryptoJS.AES.decrypt(base64Encrypted, password).toString(CryptoJS.enc.Utf8);\n" +
" document.write(html);\n" +
" document.dispatchEvent(new Event('DOMContentLoaded'));\n\n" +
" } catch (e) {\n" +
" console.error(e);\n" +
" alert(e);\n" +
" }\n" +
" }\n" +
"</script>\n" +
"</body>\n" +
"</html>";
function encrypt () {
var password = $("#password").val();
myDropzone.getFiles().forEach(function (file) {
var reader = new FileReader();
reader.onload = function() {
var html = reader.result;
var base64Enc = CryptoJS.AES.encrypt(html, password).toString();
var html = decHtmlP1 + base64Enc + decHtmlP2;
saveAs(new Blob([html],{type: 'text/html'}), 'encrypted.html');
};
reader.readAsText(file);
});
}