-
Notifications
You must be signed in to change notification settings - Fork 28
/
decrypt.js
74 lines (61 loc) · 2.04 KB
/
decrypt.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
63
64
65
66
67
68
69
70
71
72
73
74
const _do_decrypt = function (encrypted, password) {
let key = CryptoJS.enc.Utf8.parse(password);
let iv = CryptoJS.enc.Utf8.parse(password.substr(16));
let decrypted_data = CryptoJS.AES.decrypt(encrypted, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
return decrypted_data.toString(CryptoJS.enc.Utf8);
};
const _click_handler = function (element) {
let parent = element.parentNode.parentNode;
let encrypted = parent.querySelector(
".hugo-encryptor-cipher-text").innerText;
let password = parent.querySelector(
".hugo-encryptor-input").value;
password = CryptoJS.MD5(password).toString();
let index = -1;
let elements = document.querySelectorAll(
".hugo-encryptor-container");
for (index = 0; index < elements.length; ++index) {
if (elements[index].isSameNode(parent)) {
break;
}
}
let decrypted = "";
try {
decrypted = _do_decrypt(encrypted, password);
} catch (err) {
console.error(err);
alert("Failed to decrypt.");
return;
}
if (!decrypted.includes("--- DON'T MODIFY THIS LINE ---")) {
alert("Incorrect password.");
return;
}
let storage = localStorage;
let key = location.pathname + ".password." + index;
storage.setItem(key, password);
parent.innerHTML = decrypted;
}
window.onload = () => {
let index = -1;
let elements = document.querySelectorAll(
".hugo-encryptor-container");
while (1) {
++index;
let key = location.pathname + ".password." + index;
let password = localStorage.getItem(key);
if (!password) {
break;
} else {
console.log("Found password for part " + index);
let parent = elements[index];
let encrypted = parent.querySelector(".hugo-encryptor-cipher-text").innerText;
let decrypted = _do_decrypt(encrypted, password);
elements[index].innerHTML = decrypted;
}
}
};