|
1
|
|
View Code Duplication |
'use strict'; |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
function decryptAES () { |
|
4
|
|
|
|
|
5
|
|
|
const pass = String(document.getElementById('pass').value); |
|
6
|
|
|
try { |
|
7
|
|
|
|
|
8
|
|
|
var decryptionError = String(document.getElementById('decryptionError').innerHTML); |
|
9
|
|
|
var noContentError = String(document.getElementById('noContentError').innerHTML); |
|
10
|
|
|
|
|
11
|
|
|
} catch (e) { |
|
12
|
|
|
|
|
13
|
|
|
decryptionError = 'Incorrect Password!'; |
|
14
|
|
|
noContentError = 'No content to display!'; |
|
15
|
|
|
|
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
try { |
|
19
|
|
|
|
|
20
|
|
|
let content = CryptoJS.AES.decrypt(document.getElementById('encrypt-blog').innerHTML.trim(), pass); |
|
|
|
|
|
|
21
|
|
|
content = content.toString(CryptoJS.enc.Utf8); |
|
22
|
|
|
content = decodeBase64(content); |
|
23
|
|
|
content = unescape(content); |
|
24
|
|
|
if (content === '') { |
|
25
|
|
|
|
|
26
|
|
|
throw new Error(noContentError); // ??? |
|
27
|
|
|
|
|
28
|
|
|
} else { |
|
29
|
|
|
|
|
30
|
|
|
document.getElementById('encrypt-blog').style.display = 'inline'; |
|
31
|
|
|
document.getElementById('encrypt-blog').innerHTML = ''; |
|
32
|
|
|
// Use jquery to load some js code |
|
33
|
|
|
$('#encrypt-blog').html(content); |
|
34
|
|
|
document.getElementById('security').style.display = 'none'; |
|
35
|
|
|
if (document.getElementById('toc-div')) { |
|
36
|
|
|
|
|
37
|
|
|
document.getElementById('toc-div').style.display = 'inline'; |
|
38
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
// Call MathJax to render |
|
43
|
|
|
if(typeof MathJax !== 'undefined') { |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
MathJax.Hub.Queue( |
|
46
|
|
|
['resetEquationNumbers', MathJax.InputJax.TeX, ], |
|
47
|
|
|
['PreProcess', MathJax.Hub, ], |
|
48
|
|
|
['Reprocess', MathJax.Hub, ] |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
} catch (e) { |
|
54
|
|
|
|
|
55
|
|
|
alert(decryptionError); |
|
56
|
|
|
console.log(e); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
function htmlDecode (str) { |
|
63
|
|
|
|
|
64
|
|
|
let s = ''; |
|
65
|
|
|
if (str.length == 0) { |
|
66
|
|
|
|
|
67
|
|
|
return ''; |
|
68
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
s = str.replace(/>/g, '&'); |
|
72
|
|
|
s = s.replace(/</g, '<'); |
|
73
|
|
|
s = s.replace(/>/g, '>'); |
|
74
|
|
|
s = s.replace(/ /g, ' '); // ??? why not ' ' |
|
75
|
|
|
s = s.replace(/'/g, '\''); |
|
76
|
|
|
s = s.replace(/"/g, '"'); |
|
77
|
|
|
s = s.replace(/<br>/g, '\n'); |
|
78
|
|
|
return s; |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
function decodeBase64 (content) { |
|
83
|
|
|
|
|
84
|
|
|
content = CryptoJS.enc.Base64.parse(content); |
|
|
|
|
|
|
85
|
|
|
content = CryptoJS.enc.Utf8.stringify(content); |
|
86
|
|
|
return content; |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
// Since you decided to use jQuery. |
|
91
|
|
|
$(document).ready( |
|
92
|
|
|
function () { |
|
93
|
|
|
|
|
94
|
|
|
console.log('Registering Enter for decrypt.'); |
|
|
|
|
|
|
95
|
|
|
document.getElementById('pass').onkeypress = function (keyPressEvent) { |
|
96
|
|
|
|
|
97
|
|
|
if (keyPressEvent.keyCode === 13) { |
|
98
|
|
|
|
|
99
|
|
|
decryptAES(); |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
}; |
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
); |
|
107
|
|
|
|