-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt.js
More file actions
71 lines (55 loc) · 1.46 KB
/
Copy pathdecrypt.js
File metadata and controls
71 lines (55 loc) · 1.46 KB
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
$(function () {
var body = $("body"),
stage = $("#stage"),
back = $("a.back");
$("#step1 .button").click(function () {
$(this).parent().find("input").click();
});
var file = null;
$("#step1").on("change", "#input-decrypt", function (e) {
if (e.target.files.length != 1) {
alert("Please select a file to decrypt!");
return false;
}
file = e.target.files[0];
step(2);
});
$("a.button.process").click(function () {
var input = $(this).parent().find("input[type=password]"),
a = $("#step3 a.download"),
password = input.val();
input.val("");
if (password.length < 5) {
alert("Please choose a longer password!");
return;
}
var reader = new FileReader();
reader.onload = function (e) {
var decrypted = CryptoJS.AES.decrypt(e.target.result, password).toString(
CryptoJS.enc.Latin1
);
if (!/^data:/.test(decrypted)) {
alert("Invalid pass phrase or file! Please try again.");
return false;
}
a.attr("href", decrypted);
a.attr("download", file.name.replace(".encrypted", ""));
step(3);
};
reader.readAsText(file);
});
back.click(function () {
$("#step1 input[type=file]").replaceWith(function () {
return $(this).clone();
});
step(1);
});
function step(i) {
if (i == 1) {
back.fadeOut();
} else {
back.fadeIn();
}
stage.css("top", -(i - 1) * 100 + "%");
}
});