1
|
|
|
'use strict'; |
2
|
|
|
|
3
|
|
|
function decryptAES() { |
4
|
|
|
var pass = String(document.getElementById("pass").value); |
5
|
|
|
try { |
6
|
|
|
var content = CryptoJS.AES.decrypt(document.getElementById("encrypt-blog").innerHTML.trim(), pass); |
|
|
|
|
7
|
|
|
content = content.toString(CryptoJS.enc.Utf8); |
8
|
|
|
content = decodeBase64(content); |
9
|
|
|
content = unescape(content); |
10
|
|
|
if (content === "") { |
11
|
|
|
throw new Error("内容为空"); // ??? |
12
|
|
|
} else { |
13
|
|
|
document.getElementById("encrypt-blog").style.display = "inline"; |
14
|
|
|
document.getElementById("encrypt-blog").innerHTML = ""; |
15
|
|
|
// use jquery to load some js code |
16
|
|
|
$("#encrypt-blog").html(content); |
17
|
|
|
document.getElementById("security").style.display = "none"; |
18
|
|
|
if (document.getElementById("toc-div")) { |
19
|
|
|
document.getElementById("toc-div").style.display = "inline"; |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
// Call MathJax to render |
23
|
|
|
if(typeof MathJax !== "undefined") { |
|
|
|
|
24
|
|
|
MathJax.Hub.Queue( |
25
|
|
|
['resetEquationNumbers', MathJax.InputJax.TeX], |
26
|
|
|
['PreProcess', MathJax.Hub], |
27
|
|
|
['Reprocess', MathJax.Hub] |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
} catch (e) { |
31
|
|
|
alert("解密失败"); |
32
|
|
|
console.log(e); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function htmlDecode (str) { |
37
|
|
|
var s = ""; |
38
|
|
|
if (str.length == 0) return ""; |
|
|
|
|
39
|
|
|
|
40
|
|
|
s = str.replace(/>/g, "&"); |
41
|
|
|
s = s.replace(/</g, "<"); |
42
|
|
|
s = s.replace(/>/g, ">"); |
43
|
|
|
s = s.replace(/ /g, " "); // ??? why not ' ' |
44
|
|
|
s = s.replace(/'/g, "\'"); |
45
|
|
|
s = s.replace(/"/g, "\""); |
46
|
|
|
s = s.replace(/<br>/g, "\n"); |
47
|
|
|
return s; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
function decodeBase64(content) { |
51
|
|
|
content = CryptoJS.enc.Base64.parse(content); |
|
|
|
|
52
|
|
|
content = CryptoJS.enc.Utf8.stringify(content); |
53
|
|
|
return content; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// Since you decided to use jQuery. |
57
|
|
|
$(document).ready( |
58
|
|
|
function(){ |
59
|
|
|
console.log("Registering Enter for decrypt."); |
|
|
|
|
60
|
|
|
document.getElementById("pass").onkeypress = function(keyPressEvent) { |
61
|
|
|
if (keyPressEvent.keyCode === 13) { |
62
|
|
|
decryptAES(); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
); |
67
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.