Skip to content

Commit

Permalink
Merge pull request #7 from binance/v0.4.0
Browse files Browse the repository at this point in the history
v0.4.0 release
  • Loading branch information
2pd authored Apr 26, 2023
2 parents c32d320 + 7fd7126 commit 2806349
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## v0.4.0
- Add support for `ed25519` keys

## v0.3.1
- Fix tooltip on canceled save
- Update dependencies
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RSA Key Generator
# Key Pair Generator

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

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

Expand Down Expand Up @@ -43,7 +43,7 @@ npm run dist

1. Open the app;

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

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;

Expand Down
15 changes: 8 additions & 7 deletions assets/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link href="../css/daisyui.css" rel="stylesheet" type="text/css" />
<script src="../js/tailwind.js"></script>
<link href="../css/styles.css" rel="stylesheet">
<title>RSA Key Generator</title>
<title>Key Pair Generator</title>
</head>

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

<div class="overflow-x-auto py-2">
<p id="info">You can generate an RSA PKCS#8 private key with the help of this tool. In addition, it will
<p id="info">You can generate private keys with the help of this tool. In addition, it will
display the
public key of the generated or pasted private key.</p>
public key of the generated or pasted private key. The available format is PKCS#8.</p>
</div>
<div class="grid grid-cols-3 gap-x-8 w-2/4 py-2">
<div class="grid grid-cols-3 gap-x-8 w-3/4 py-2">
<div>
<select id="select-bits" class="select select-bordered">
<option value="2048">2048 bit</option>
<option value="4096">4096 bit</option>
<select id="select-keyType" class="select select-bordered">
<option value="rsa-2048">RSA (2048 bits)</option>
<option value="rsa-4096">RSA (4096 bits)</option>
<option value="ed25519">Ed25519</option>
</select>
</div>
<div class="col-span-2 pl-4">
Expand Down
4 changes: 2 additions & 2 deletions assets/js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function remove_label_text(label_id) {

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

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rsa-key-generator",
"version": "0.3.1",
"description": "RSA Key Generator",
"version": "0.4.0",
"description": "Key Pair Generator",
"main": "src/main.js",
"scripts": {
"start": "electron .",
Expand Down
61 changes: 43 additions & 18 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
GET_ALL_CHANNELS
} = require('./shared')

function createWindow () {
function createWindow() {
let options = {
width: 800,
height: 600,
Expand Down Expand Up @@ -49,7 +49,7 @@ function createWindow () {

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

// mainWindow.webContents.openDevTools()
//mainWindow.webContents.openDevTools()
}

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

// Actions
async function generateKeys (bits) {
return generateKeyPairSync('rsa', {
modulusLength: bits,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
})
async function generateKeys(keyType) {
if (keyType === 'rsa-2048') {
return generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
})
} else if (keyType === 'rsa-4096') {
return generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
})
} else {
return generateKeyPairSync('ed25519', {
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
})
}
}

async function generatePublicKey (privateKey) {
async function generatePublicKey(privateKey) {
try {
const publickKeyObject = createPublicKey(privateKey)
return publickKeyObject.export({ format: 'pem', type: 'spki' })
Expand All @@ -89,11 +114,11 @@ async function generatePublicKey (privateKey) {
}
}

async function copyKey (data) {
async function copyKey(data) {
clipboard.writeText(data)
}

async function saveKey (keyType, key) {
async function saveKey(keyType, key) {
const options = {
title: `Save ${keyType}`,
defaultPath: keyType,
Expand All @@ -108,7 +133,7 @@ async function saveKey (keyType, key) {
const result = await dialog.showSaveDialog(null, options).then(({ canceled, filePath }) => {
if (!canceled) {
try {
fs.writeFileSync(filePath, key, 'utf-8')
fs.writeFileSync(filePath, key, { encoding: "utf8", mode: 0o600 })
return "Key saved"
} catch (err) {
return `Error. Can not save file ${filePath}`
Expand Down
2 changes: 1 addition & 1 deletion src/preload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { contextBridge, ipcRenderer } = require('electron')

contextBridge.exposeInMainWorld('utils', {
generateKeys: (bits) => ipcRenderer.invoke('generate_keys', bits),
generateKeys: (keyType) => ipcRenderer.invoke('generate_keys', keyType),
generatePublicKey: (privateKey) => ipcRenderer.invoke('generate_public_key', privateKey),
copyKey: (data) => ipcRenderer.invoke('copy_key', data),
saveKey: (keyType, key) => ipcRenderer.invoke('save_key', keyType, key)
Expand Down

0 comments on commit 2806349

Please sign in to comment.