Skip to content

Commit dc47863

Browse files
committed
Merge branch 'feat/rsa-keygen-enhancements' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # vite.config.ts
2 parents cfeef64 + 85aed08 commit dc47863

File tree

6 files changed

+119
-36
lines changed

6 files changed

+119
-36
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "it-tools",
33
"version": "2024.10.22-7ca5933",
44
"packageManager": "[email protected]",
5+
"version": "2023.11.2-7d94e11",
56
"description": "Collection of handy online tools for developers, with great UX. ",
67
"author": "Corentin Th <[email protected]> (https://corentin.tech)",
78
"license": "GNU GPLv3",
@@ -307,6 +308,7 @@
307308
"vue-i18n": "^9.9.1",
308309
"vue-mathjax-next": "^0.0.6",
309310
"vue-markdown-render": "^2.2.1",
311+
"vue-i18n": "^9.2.2",
310312
"vue-router": "^4.1.6",
311313
"vue-shadow-dom": "^4.2.0",
312314
"vue-tsc": "^1.8.1",
@@ -324,7 +326,7 @@
324326
"devDependencies": {
325327
"@antfu/eslint-config": "^0.41.0",
326328
"@iconify-json/mdi": "^1.1.50",
327-
"@intlify/unplugin-vue-i18n": "^2.0.0",
329+
"@intlify/unplugin-vue-i18n": "^0.13.0",
328330
"@playwright/test": "^1.32.3",
329331
"@rushstack/eslint-patch": "^1.2.0",
330332
"@tsconfig/node18": "^18.2.0",

pnpm-lock.yaml

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/rsa-key-pair-generator/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { translate } from '@/plugins/i18n.plugin';
55
export const tool = defineTool({
66
name: translate('tools.rsa-key-pair-generator.title'),
77
path: '/rsa-key-pair-generator',
8-
description: translate('tools.rsa-key-pair-generator.description'),
9-
keywords: ['rsa', 'key', 'pair', 'generator', 'public', 'private', 'secret', 'ssh', 'pem'],
8+
description: 'Generate new random RSA private and public keys (with or without passphrase).',
9+
keywords: ['rsa', 'key', 'pair', 'generator', 'public', 'private', 'secret', 'ssh', 'pem', 'passphrase', 'password'],
1010
component: () => import('./rsa-key-pair-generator.vue'),
1111
icon: Certificate,
1212
npmPackages: ['node-forge'],

src/tools/rsa-key-pair-generator/rsa-key-pair-generator.service.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { pki } from 'node-forge';
22
import workerScript from 'node-forge/dist/prime.worker.min?url';
3+
import sshpk from 'sshpk';
34

45
export { generateKeyPair };
56

@@ -16,11 +17,39 @@ function generateRawPairs({ bits = 2048 }) {
1617
);
1718
}
1819

19-
async function generateKeyPair(config: { bits?: number } = {}) {
20+
async function generateKeyPair(config: {
21+
bits?: number
22+
password?: string
23+
format?: sshpk.PrivateKeyFormatType
24+
comment?: string
25+
} = {}) {
2026
const { privateKey, publicKey } = await generateRawPairs(config);
2127

28+
const privateUnencryptedKeyPem = pki.privateKeyToPem(privateKey);
29+
30+
if (config?.format === 'pem') {
31+
return {
32+
publicKey: pki.publicKeyToPem(publicKey),
33+
privateKey: config?.password
34+
? pki.encryptRsaPrivateKey(privateKey, config?.password)
35+
: privateUnencryptedKeyPem,
36+
};
37+
}
38+
39+
const privKey = sshpk.parsePrivateKey(privateUnencryptedKeyPem);
40+
privKey.comment = config?.comment;
41+
const pubFormat = config.format ?? 'ssh';
42+
let privFormat = config.format ?? 'ssh';
43+
if (privFormat === 'ssh') {
44+
privFormat = 'ssh-private';
45+
}
46+
const pubKey = privKey.toPublic();
2247
return {
23-
publicKeyPem: pki.publicKeyToPem(publicKey),
24-
privateKeyPem: pki.privateKeyToPem(privateKey),
48+
publicKey: pubKey.toString(pubFormat),
49+
privateKey: config?.password
50+
? privKey.toString(privFormat,
51+
{ passphrase: config?.password, comment: config?.comment },
52+
)
53+
: privKey.toString(privFormat, { comment: config?.comment }),
2554
};
2655
}
Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
<script setup lang="ts">
2+
import type sshpk from 'sshpk';
23
import { generateKeyPair } from './rsa-key-pair-generator.service';
34
import TextareaCopyable from '@/components/TextareaCopyable.vue';
45
import { withDefaultOnErrorAsync } from '@/utils/defaults';
56
import { useValidation } from '@/composable/validation';
67
import { computedRefreshableAsync } from '@/composable/computedRefreshable';
78
89
const bits = ref(2048);
9-
const emptyCerts = { publicKeyPem: '', privateKeyPem: '' };
10+
const comment = ref('');
11+
const password = ref('');
12+
const emptyCerts = { publicKey: '', privateKey: '' };
13+
14+
const format = useStorage('rsa-key-pair-generator:format', 'ssh');
15+
const formatOptions = [
16+
{ value: 'pem', label: 'PEM' },
17+
{ value: 'pkcs1', label: 'PKCS#1' },
18+
{ value: 'pkcs8', label: 'PKCS#8' },
19+
{ value: 'ssh', label: 'OpenSSH Standard' },
20+
{ value: 'openssh', label: 'OpenSSH New' },
21+
{ value: 'putty', label: 'PuTTY' },
22+
];
23+
24+
const supportsPassphrase = computed(() => format.value === 'pem' || format.value === 'ssh');
1025
1126
const { attrs: bitsValidationAttrs } = useValidation({
1227
source: bits,
@@ -19,31 +34,67 @@ const { attrs: bitsValidationAttrs } = useValidation({
1934
});
2035
2136
const [certs, refreshCerts] = computedRefreshableAsync(
22-
() => withDefaultOnErrorAsync(() => generateKeyPair({ bits: bits.value }), emptyCerts),
37+
() => withDefaultOnErrorAsync(() => generateKeyPair({
38+
bits: bits.value,
39+
password: password.value,
40+
format: format.value as sshpk.PrivateKeyFormatType,
41+
comment: comment.value,
42+
}), emptyCerts),
2343
emptyCerts,
2444
);
2545
</script>
2646

2747
<template>
28-
<div style="flex: 0 0 100%">
29-
<div item-style="flex: 1 1 0" style="max-width: 600px" mx-auto flex gap-3>
30-
<n-form-item label="Bits :" v-bind="bitsValidationAttrs as any" label-placement="left" label-width="100">
48+
<div>
49+
<n-space justify="space-between" mb-1>
50+
<c-select
51+
v-model:value="format"
52+
label-position="left"
53+
label="Format:"
54+
:options="formatOptions"
55+
placeholder="Select a key format"
56+
/>
57+
58+
<n-form-item label="Bits :" v-bind="bitsValidationAttrs as any" label-placement="left">
3159
<n-input-number v-model:value="bits" min="256" max="16384" step="8" />
3260
</n-form-item>
61+
</n-space>
3362

63+
<div v-if="supportsPassphrase" mb-1>
64+
<n-form-item label="Passphrase :" label-placement="left">
65+
<n-input
66+
v-model:value="password"
67+
type="password"
68+
show-password-on="mousedown"
69+
placeholder="Passphrase"
70+
/>
71+
</n-form-item>
72+
</div>
73+
74+
<div mb-1>
75+
<n-form-item label="Comment :" label-placement="left">
76+
<n-input
77+
v-model:value="comment"
78+
type="text"
79+
placeholder="Comment"
80+
/>
81+
</n-form-item>
82+
</div>
83+
84+
<n-space justify="center" mb-1>
3485
<c-button @click="refreshCerts">
3586
Refresh key-pair
3687
</c-button>
37-
</div>
38-
</div>
88+
</n-space>
3989

40-
<div>
41-
<h3>Public key</h3>
42-
<TextareaCopyable :value="certs.publicKeyPem" />
43-
</div>
90+
<div>
91+
<h3>Public key</h3>
92+
<TextareaCopyable :value="certs.publicKey" :word-wrap="true" />
93+
</div>
4494

45-
<div>
46-
<h3>Private key</h3>
47-
<TextareaCopyable :value="certs.privateKeyPem" />
95+
<div>
96+
<h3>Private key</h3>
97+
<TextareaCopyable :value="certs.privateKey" />
98+
</div>
4899
</div>
49100
</template>

vite.config.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { resolve } from 'node:path';
21
import { URL, fileURLToPath } from 'node:url';
2+
import { resolve } from 'node:path';
33
import { nodePolyfills } from 'vite-plugin-node-polyfills';
44

5-
import VueI18n from '@intlify/unplugin-vue-i18n/vite';
5+
import { defineConfig } from 'vite';
66
import vue from '@vitejs/plugin-vue';
77
import vueJsx from '@vitejs/plugin-vue-jsx';
88
import Unocss from 'unocss/vite';
@@ -12,12 +12,19 @@ import Icons from 'unplugin-icons/vite';
1212
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
1313
import Components from 'unplugin-vue-components/vite';
1414
import { defineConfig } from 'vite';
15-
import { nodePolyfills } from 'vite-plugin-node-polyfills';
1615
import { VitePWA } from 'vite-plugin-pwa';
1716
import markdown from 'vite-plugin-vue-markdown';
1817
import svgLoader from 'vite-svg-loader';
18+
import { VitePWA } from 'vite-plugin-pwa';
19+
import AutoImport from 'unplugin-auto-import/vite';
20+
import Components from 'unplugin-vue-components/vite';
21+
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
22+
import Unocss from 'unocss/vite';
1923
import { configDefaults } from 'vitest/config';
2024
import topLevelAwait from "vite-plugin-top-level-await";
25+
import Icons from 'unplugin-icons/vite';
26+
import IconsResolver from 'unplugin-icons/resolver';
27+
import VueI18n from '@intlify/unplugin-vue-i18n/vite';
2128

2229
const baseUrl = process.env.BASE_URL ?? '/';
2330

@@ -26,13 +33,9 @@ export default defineConfig({
2633
plugins: [
2734
VueI18n({
2835
runtimeOnly: true,
29-
jitCompilation: true,
3036
compositionOnly: true,
3137
fullInstall: true,
32-
strictMessage: false,
33-
include: [
34-
resolve(__dirname, 'locales/**'),
35-
],
38+
include: [resolve(__dirname, 'locales/**')],
3639
}),
3740
AutoImport({
3841
imports: [

0 commit comments

Comments
 (0)