-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpreload.js
83 lines (81 loc) · 2.8 KB
/
preload.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
const { contextBridge, remote } = require('electron'); // Bridge some functions
const { dialog } = require('electron').remote;
const keygenAES = require('./js/backend/lib/aes_keygen_lib.min');
const keygenRSA = require('./js/backend/lib/keyGen_lib.min');
const encryptAES = require('./js/backend/lib/aes_encryptor_lib.min');
const decryptAES = require('./js/backend/lib/aes_decryptor_lib.min');
const fEncAES = require('./js/backend/lib/file_enc_lib.min');
const fDecAES = require('./js/backend/lib/file_dec_lib.min');
const RSAEncDec = require('./js/backend/lib/encryptor_lib.min');
// Expose close, max- and mini-mise functions
const win = remote.getCurrentWindow();
contextBridge.exposeInMainWorld('winCtl', {
close: () => { win.close(); },
max: () =>
{
if (win.isFullScreen()) win.setFullScreen(false);
else win.setFullScreen(true);
},
min: () => { win.minimize(); },
restore: () => { win.unmaximize(); }
});
contextBridge.exposeInMainWorld('fileOps', {
fileOpen: (customTitle, label, dialogOps, filter) => { // High risk function
return dialog.showOpenDialog(win, {
title: customTitle, // Window title for Windows
message: customTitle, // Selector window title for macOS
properties: dialogOps,
filters: filter,
buttonLabel: label
});
},
filePick: (customTitle, label, ops, filter, defName='Untitled') => {
return dialog.showSaveDialog(win, {
title: customTitle,
message: customTitle,
nameFieldLabel: label,
properties: ops,
filters: filter,
defaultPath: defName
})
}
});
// AES operations
contextBridge.exposeInMainWorld('aesCrypto', {
keygen: (filename) => { // Generate AES keyfiles
return keygenAES.gen(filename);
},
encrypt: (plainText, loc) => {
return encryptAES.encrypt(plainText, loc);
},
decrypt: (cipher, iv, loc) => {
return decryptAES.decrypt(cipher, iv, loc);
}
});
contextBridge.exposeInMainWorld('fileCrypto', {
encrypt: (fileIn, fileOut, key) => {
return fEncAES.encrypt(fileIn, fileOut, key);
},
decrypt: (fileIn, fileOut, key) => {
return fDecAES.decrypt(fileIn, fileOut, key);
}
});
// RSA operations
contextBridge.exposeInMainWorld('rsaCrypto', {
keygen: (len, pwd, loc, cb) => { // Generate AES keyfiles
return keygenRSA.gen(len, pwd, loc, cb);
},
encrypt: (pub, aes, out) => {
return RSAEncDec.encrypt(pub, aes, out);
},
decrypt: (pub, pwd, aes, out) => {
return RSAEncDec.decrypt(pub, pwd, aes, out);
}
});
// System info
contextBridge.exposeInMainWorld('proInfo', {
platform: () => { // Get platform
return process.platform;
}
});
require('electron')