Skip to content

Commit 2806349

Browse files
authored
Merge pull request #7 from binance/v0.4.0
v0.4.0 release
2 parents c32d320 + 7fd7126 commit 2806349

8 files changed

+64
-35
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG
22

3+
## v0.4.0
4+
- Add support for `ed25519` keys
5+
36
## v0.3.1
47
- Fix tooltip on canceled save
58
- Update dependencies

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# RSA Key Generator
1+
# Key Pair Generator
22

3-
This simple tool can be used to generate an RSA PKCS#8 key pair (private and public key).
3+
This simple tool can be used to generate an RSA and Ed25519 PKCS#8 key pairs (private and public key).
44

55
There's two methods to run the tool, you can either download or build from source code.
66

@@ -43,7 +43,7 @@ npm run dist
4343

4444
1. Open the app;
4545

46-
2. Choose the bits size; Recommend to keep the default value (`2048`), then click the button `Generate Key Pair`;
46+
2. Choose the key type; Recommend to keep the default value (` RSA 2048`), then click the button `Generate Key Pair`;
4747

4848
3. Below on the left column is the `Private Key`, which should be stored in a secure location on your local disk (by using the `Save` button) and must never be shared with anyone;
4949

assets/html/index.html

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<link href="../css/daisyui.css" rel="stylesheet" type="text/css" />
99
<script src="../js/tailwind.js"></script>
1010
<link href="../css/styles.css" rel="stylesheet">
11-
<title>RSA Key Generator</title>
11+
<title>Key Pair Generator</title>
1212
</head>
1313

1414
<body>
@@ -20,15 +20,16 @@ <h1 class="text-3xl font-bold">Generate</h1>
2020
</div>
2121

2222
<div class="overflow-x-auto py-2">
23-
<p id="info">You can generate an RSA PKCS#8 private key with the help of this tool. In addition, it will
23+
<p id="info">You can generate private keys with the help of this tool. In addition, it will
2424
display the
25-
public key of the generated or pasted private key.</p>
25+
public key of the generated or pasted private key. The available format is PKCS#8.</p>
2626
</div>
27-
<div class="grid grid-cols-3 gap-x-8 w-2/4 py-2">
27+
<div class="grid grid-cols-3 gap-x-8 w-3/4 py-2">
2828
<div>
29-
<select id="select-bits" class="select select-bordered">
30-
<option value="2048">2048 bit</option>
31-
<option value="4096">4096 bit</option>
29+
<select id="select-keyType" class="select select-bordered">
30+
<option value="rsa-2048">RSA (2048 bits)</option>
31+
<option value="rsa-4096">RSA (4096 bits)</option>
32+
<option value="ed25519">Ed25519</option>
3233
</select>
3334
</div>
3435
<div class="col-span-2 pl-4">

assets/js/renderer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function remove_label_text(label_id) {
1313

1414
// Actions
1515
const generateKeys = async () => {
16-
bits = document.getElementById('select-bits').value
17-
let { privateKey, publicKey } = await window.utils.generateKeys(parseInt(bits))
16+
keyType = document.getElementById('select-keyType').value
17+
let { privateKey, publicKey } = await window.utils.generateKeys(keyType)
1818
document.getElementById('private-key-text-area').value = privateKey
1919
document.getElementById('public-key-text-area').value = publicKey
2020

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rsa-key-generator",
3-
"version": "0.3.1",
4-
"description": "RSA Key Generator",
3+
"version": "0.4.0",
4+
"description": "Key Pair Generator",
55
"main": "src/main.js",
66
"scripts": {
77
"start": "electron .",

src/main.js

+43-18
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const {
1111
GET_ALL_CHANNELS
1212
} = require('./shared')
1313

14-
function createWindow () {
14+
function createWindow() {
1515
let options = {
1616
width: 800,
1717
height: 600,
@@ -49,7 +49,7 @@ function createWindow () {
4949

5050
mainWindow.loadFile('assets/html/index.html')
5151

52-
// mainWindow.webContents.openDevTools()
52+
//mainWindow.webContents.openDevTools()
5353
}
5454

5555
app.whenReady().then(() => {
@@ -66,21 +66,46 @@ app.on('window-all-closed', function () {
6666
})
6767

6868
// Actions
69-
async function generateKeys (bits) {
70-
return generateKeyPairSync('rsa', {
71-
modulusLength: bits,
72-
publicKeyEncoding: {
73-
type: 'spki',
74-
format: 'pem'
75-
},
76-
privateKeyEncoding: {
77-
type: 'pkcs8',
78-
format: 'pem'
79-
}
80-
})
69+
async function generateKeys(keyType) {
70+
if (keyType === 'rsa-2048') {
71+
return generateKeyPairSync('rsa', {
72+
modulusLength: 2048,
73+
publicKeyEncoding: {
74+
type: 'spki',
75+
format: 'pem'
76+
},
77+
privateKeyEncoding: {
78+
type: 'pkcs8',
79+
format: 'pem'
80+
}
81+
})
82+
} else if (keyType === 'rsa-4096') {
83+
return generateKeyPairSync('rsa', {
84+
modulusLength: 4096,
85+
publicKeyEncoding: {
86+
type: 'spki',
87+
format: 'pem'
88+
},
89+
privateKeyEncoding: {
90+
type: 'pkcs8',
91+
format: 'pem'
92+
}
93+
})
94+
} else {
95+
return generateKeyPairSync('ed25519', {
96+
publicKeyEncoding: {
97+
type: 'spki',
98+
format: 'pem'
99+
},
100+
privateKeyEncoding: {
101+
type: 'pkcs8',
102+
format: 'pem'
103+
}
104+
})
105+
}
81106
}
82107

83-
async function generatePublicKey (privateKey) {
108+
async function generatePublicKey(privateKey) {
84109
try {
85110
const publickKeyObject = createPublicKey(privateKey)
86111
return publickKeyObject.export({ format: 'pem', type: 'spki' })
@@ -89,11 +114,11 @@ async function generatePublicKey (privateKey) {
89114
}
90115
}
91116

92-
async function copyKey (data) {
117+
async function copyKey(data) {
93118
clipboard.writeText(data)
94119
}
95120

96-
async function saveKey (keyType, key) {
121+
async function saveKey(keyType, key) {
97122
const options = {
98123
title: `Save ${keyType}`,
99124
defaultPath: keyType,
@@ -108,7 +133,7 @@ async function saveKey (keyType, key) {
108133
const result = await dialog.showSaveDialog(null, options).then(({ canceled, filePath }) => {
109134
if (!canceled) {
110135
try {
111-
fs.writeFileSync(filePath, key, 'utf-8')
136+
fs.writeFileSync(filePath, key, { encoding: "utf8", mode: 0o600 })
112137
return "Key saved"
113138
} catch (err) {
114139
return `Error. Can not save file ${filePath}`

src/preload.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { contextBridge, ipcRenderer } = require('electron')
22

33
contextBridge.exposeInMainWorld('utils', {
4-
generateKeys: (bits) => ipcRenderer.invoke('generate_keys', bits),
4+
generateKeys: (keyType) => ipcRenderer.invoke('generate_keys', keyType),
55
generatePublicKey: (privateKey) => ipcRenderer.invoke('generate_public_key', privateKey),
66
copyKey: (data) => ipcRenderer.invoke('copy_key', data),
77
saveKey: (keyType, key) => ipcRenderer.invoke('save_key', keyType, key)

0 commit comments

Comments
 (0)