-
Notifications
You must be signed in to change notification settings - Fork 0
/
ciphrixa.js
139 lines (119 loc) · 4.15 KB
/
ciphrixa.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const { ipcRenderer, remote } = require('electron');
const Cryptr = require('cryptr');
dialog = remote.dialog;
//Encrypt String
function encryptString() {
var inp = document.getElementById("enc_str_input").value;
var key = document.getElementById("enc_str_input_key").value;
var out = document.getElementById("enc_str_output");
if (inp == "" || key == "") {
M.toast({html: "<i class='material-icons left'>warning</i> String and Key cant be empty!"});
return false;
}
var cr = new Cryptr(key);
var enc = cr.encrypt(inp);
out.innerHTML = enc;
M.toast({html: "<i class='material-icons left'>done</i> String Encrypted"});
}
//Decrypt String
function decryptString() {
var inp = document.getElementById("dec_str_input").value;
var key = document.getElementById("dec_str_input_key").value;
var out = document.getElementById("dec_str_output");
if (inp == "" || key == "") {
M.toast({html: "<i class='material-icons left'>warning</i> String and Key cant be empty!"});
return false;
}
var cr = new Cryptr(key);
try {
var dec = cr.decrypt(inp);
} catch(e) {
M.toast({html: "<i class='material-icons left'>error</i> String failed to Decrypt: Wrong Key"});
out.innerHTML = "Failed to Decrypt";
return;
}
out.innerHTML = dec;
M.toast({html: "<i class='material-icons left'>done</i> String Decrypted"});
}
//Encrypt File
function encryptFile() {
var inp = document.getElementById("enc_file_input").files[0];
var key = document.getElementById("enc_file_input_key").value;
if (inp.length == 0 || key == "") {
M.toast({html: "<i class='material-icons left'>warning</i> File and Key cant be empty!"});
return false;
}
var reader = new FileReader();
reader.readAsText(inp, "UTF-8");
reader.onload = function (evt) {
var txt = evt.target.result;
var cr = new Cryptr(key);
var enc = cr.encrypt(txt);
let Data = {
type: "saveFile",
filename: inp.name + ".enc",
contents: enc,
allowed: "enc"
};
ipcRenderer.send('request-mainprocess-action', Data);
M.toast({html: "<i class='material-icons left'>done</i> File Encrypted"});
}
reader.onerror = function (evt) {
M.toast({html: "<i class='material-icons left'>error</i> Failed to read file"});
return false;
}
}
//Decrypt File
function decryptFile() {
var inp = document.getElementById("dec_file_input").files[0];
var key = document.getElementById("dec_file_input_key").value;
if (inp.length == 0 || key == "") {
M.toast({html: "<i class='material-icons left'>warning</i> File and Key cant be empty!"});
return false;
}
var reader = new FileReader();
reader.readAsText(inp, "UTF-8");
reader.onload = function (evt) {
var txt = evt.target.result;
var cr = new Cryptr(key);
try {
var dec = cr.decrypt(txt);
} catch(e) {
M.toast({html: "<i class='material-icons left'>error</i> File failed to Decrypt: Wrong Key"});
return;
}
let Data = {
type: "saveFile",
filename: inp.name + ".dec",
contents: dec,
allowed: "dec"
};
ipcRenderer.send('request-mainprocess-action', Data);
M.toast({html: "<i class='material-icons left'>done</i> File Decrypted"});
}
reader.onerror = function (evt) {
M.toast({html: "<i class='material-icons left'>error</i> Failed to read file"});
return false;
}
}
//AUTO UPDATER
const notification = document.getElementById('notification');
const message = document.getElementById('message');
const restartButton = document.getElementById('restart-button');
ipcRenderer.on('update_available', () => {
ipcRenderer.removeAllListeners('update_available');
message.innerText = 'A new update is available. Downloading now...';
notification.classList.remove('hidden');
});
ipcRenderer.on('update_downloaded', () => {
ipcRenderer.removeAllListeners('update_downloaded');
message.innerText = 'Update Downloaded. It will be installed on restart. Restart now?';
restartButton.classList.remove('hidden');
notification.classList.remove('hidden');
});
function closeNotification() {
notification.classList.add('hidden');
}
function restartApp() {
ipcRenderer.send('restart_app');
}