-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
152 lines (134 loc) · 6.5 KB
/
main.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
140
141
142
143
144
145
146
147
148
149
150
151
152
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
delete global.TransformStream
const openpgp = require('openpgp') // use as CommonJS, AMD, ES6 module or via window.openpgp
openpgp.initWorker({ path:'openpgp.worker.js' }) // set the relative web worker path
// put keys in backtick (``) to avoid errors caused by spaces or tabs
const pubkey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: BCPG C# v1.6.1.0
mQENBFy7JRQBCACUunBskVvgUy2dzITf7oWkSIhwBcQBv6fESb2E/64Pi2T4deJv
msw3oALCynWEG+Em2fabFCk3UjRVvxPHSCgpMCIZ2S74E6xYHbk1aOcesytyrv4n
phciJh73Jqeph1vPjCsIOqWA2TSOiAose4w00DKpII0iOUfnFef9lWkAkCmaE2Ky
+ndvYT6xIAZXEhYX3H9D40csrX9WXCYrA+Eg0P5TUza2+lNjHLcM0e2sjosrTY8t
hq35Hr76Z1EWh56XUfMH82x+Tado4uAuN/9M2g6uPoIxn86+Pq3RKIn5zd2rQ2Ah
weD1rWo9oUMeXf7mXXUTKSqNb+sWdskPDxqbABEBAAG0AIkBHAQQAQIABgUCXLsl
FAAKCRDcoTbQC2DHX4tJB/9AgI5fjAemjxl+QS8r8tDtRPuJDiOGCbGLrK5AQ/aN
hrnYNABQqlHVd/6MGYKoCeFtiVeJ6740utdyqEP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oR95miE1TTL/qiJbP4ulqVC9bRx+9999CDEl244b9rHWZCvKEb5SbOa
p676GVYb9RVs5FE3QcHt/sXdtL0SDC5x8D8XmtPyrukfQ/Fg/g5SaksXVsF5TjfR
rxnKIbbBONQ4T5aqr0flrGXllDAkqdlqhoemFSmfk0XOpT3z2QL34/Z1aW7uo4Pu
EgG3HULyCDZkxzaZYlkl+fe223hkm+SgP6Q+BjvcClP/qM+B86K1+F6y5mK1pJFb
m0ITF1cXTjfvQJ07/eV9Dida/ma8fGuPcP2X5BwjJ7pV0uVF9JY8P4m2+k/OB+Ng
VEuC8PN1RIZwXgmYAXiTqTz2oHW9cIF/ovb005YroDXDsotDBXSG6JX+fdYSoVhm
/EKUCKLZ5riRQOszjBvn0JCYCTyDLadFG5/z4emGp4zl6+115xFH9S0kDonxjDL7
W8oV1rBEjA/BAYkVQ7tndtoziwd1Qig6IFXfMvwjottaYrIztaHROBt7G8JQKErX
ZkCRsOkxCDdcHnfTVt08LDb4p9icVa2eAAcvppRnV7QAiQEcBBABAgAGBQJcuyUU
AAoJENyhNtALYMdfi0kH/0CAjl+MB6aPGX5BLyvy0O1E+4kOI4YJsYusrkBD9o2G
udg0AFCqUdV3/owZgqgJ4W2JV4nrvjS613KoQ8YQ83hK+Dr7h6yXcKaoVVZ6dxiV
6rPoHJO5HBZipGhYXuvVj24rLU1iYLnKWVfRdB9BjaThXUNDqVsMAHGWVjZJtpBJ
YqDGr9IMy8EeOILJ0tJvXHNn6b9ZzJ/sEit5VKlVBo1GCJCZne9b/YI4tnpjrtF+
IaUHKZdv6/mMTTR57yYXPVVwNwi782bpfaf5kfRZVRcTWg4ZQ66XcRMNbsBaLh6z
j5ojZtcvwP60teXn0qtKT0AJ+LwVIrH4KQ3LLUv2RT8=
=ib2s
-----END PGP PRIVATE KEY BLOCK-----` //encrypted private key
const passphrase=``
const encryptDecryptFunction = () => {
openpgp.key.readArmored(privkey).then((privKeyResults) => {
const privKeyObj = privKeyResults.keys[0]
privKeyObj.decrypt(passphrase)
openpgp.key.readArmored(pubkey).then((pubKeyResults) => {
const options = {
message: openpgp.message.fromText('Hello, World!'), // input as Message object
publicKeys: pubKeyResults.keys, // for encryption
privateKeys: [privKeyObj] // for signing (optional)
}
openpgp.encrypt(options).then(ciphertext => {
encrypted = ciphertext.data // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
return encrypted
})
.then(async encrypted => {
const options = {
message: await openpgp.message.readArmored(encrypted), // parse armored message
publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for verification (optional)
privateKeys: [privKeyObj] // for decryption
}
openpgp.decrypt(options).then(plaintext => {
console.log(plaintext.data)
return plaintext.data // 'Hello, World!'
})
})
})
});
/*
var options = {
userIds: [{ name:'Jon Smith', email:'[email protected]' }], // multiple user IDs
curve: "ed25519", // ECC curve name
passphrase: 'super long and hard to guess secret' // protects the private key
};
openpgp.generateKey(options).then(function(key) {
var privkey = key.privateKeyArmored; // '-----BEGIN PGP PRIVATE KEY BLOCK ... '
var pubkey = key.publicKeyArmored; // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
var revocationCertificate = key.revocationCertificate; // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
});*/
}
encryptDecryptFunction();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) createWindow()
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.