Merge branch 'feat/pgp-keygen' into chore/all-my-stuffs

# Conflicts:
#	components.d.ts
#	pnpm-lock.yaml
#	src/tools/index.ts
This commit is contained in:
ShareVB committed 2024-11-03 23:04:18 +01:00
commit b942b4614f
4 files changed
+153

No files matched your search

+1
View File
@@ -11360,6 +11360,7 @@ packages:
/jsesc@2.5.2:
resolution: {integrity: sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==}
engines: {node: '>=4'}
hasBin: true
/jsesc@3.0.2:
resolution: {integrity: sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==}
+4
View File
@@ -128,6 +128,7 @@ import { tool as markdownEditor } from './markdown-editor';
import { tool as nanoMemo } from './nano-memo';
import { tool as option43Generator } from './option43-generator';
import { tool as pgpEncryption } from './pgp-encryption';
import { tool as pgpKeygen } from './pgp-keygen';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -274,6 +275,9 @@ export const toolsByCategory: ToolCategory[] = [
passwordStrengthAnalyser,
pdfSignatureChecker,
pgpEncryption,
passwordStrengthAnalyser,
pdfSignatureChecker,
pgpKeygen,
],
},
{
+12
View File
@@ -0,0 +1,12 @@
import { Certificate } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'PGP keygen',
path: '/pgp-key-pair-generator',
description: 'Generate new random PGP private and public keys (with or without passphrase).',
keywords: ['pgp', 'key', 'pair', 'generator', 'public', 'private', 'secret', 'ssh', 'pem', 'passphrase', 'password'],
component: () => import('./pgp-keygen.vue'),
icon: Certificate,
createdAt: new Date('2024-04-20'),
});
+136
View File
@@ -0,0 +1,136 @@
<script setup lang="ts">
import * as openpgp from 'openpgp';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
import { useValidation } from '@/composable/validation';
import { computedRefreshableAsync } from '@/composable/computedRefreshable';
const bits = ref(4096);
const username = ref('');
const useremail = ref('');
const password = ref('');
const format = useStorage('pgp-key-pair-generator:format', 'curve25519');
const formats = [
'rsa',
'curve25519',
'ed25519',
'p256', 'p384', 'p521',
'brainpoolP256r1', 'brainpoolP384r1', 'brainpoolP512r1',
'secp256k1',
];
const { attrs: bitsValidationAttrs } = useValidation({
source: bits,
rules: [
{
message: 'Bits should be 256 <= bits <= 16384 and be a multiple of 8',
validator: value => value >= 256 && value <= 16384 && value % 8 === 0,
},
],
});
const [certs, refreshCerts] = computedRefreshableAsync(
async () => {
const formatValue = format.value;
const passphrase = password.value;
const name = username.value;
const email = useremail.value;
const rsaBits = bits.value;
try {
if (format.value === 'rsa') {
const { privateKey, publicKey } = await openpgp.generateKey({
type: 'rsa', // Type of the key
rsaBits, // RSA key size (defaults to 4096 bits)
userIDs: [{ name, email }], // you can pass multiple user IDs
passphrase, // protects the private key
format: 'armored',
});
return { privateKey, publicKey, revocationCertificate: '' };
}
const { privateKey, publicKey, revocationCertificate } = await openpgp.generateKey({
type: 'ecc', // Type of the key, defaults to ECC
curve: formatValue as openpgp.EllipticCurveName, // ECC curve name, defaults to curve25519
userIDs: [{ name, email }], // you can pass multiple user IDs
passphrase, // protects the private key
format: 'armored',
});
return { privateKey, publicKey, revocationCertificate };
}
catch (e: any) {
return { privateKey: `#${e.toString()}`, publicKey: `#${e.toString()}`, revocationCertificate: '' };
}
}, { privateKey: '', publicKey: '', revocationCertificate: '' },
);
</script>
<template>
<div>
<div mb-4>
<div style="flex: 0 0 100%">
<div item-style="flex: 1 1 0" style="max-width: 600px" mx-auto flex gap-3>
<c-select
v-model:value="format"
label-position="left"
label="Format:"
:options="formats"
placeholder="Select a key format"
/>
<n-form-item v-if="format === 'rsa'" label="RSA Bits :" v-bind="bitsValidationAttrs as any" label-placement="left">
<n-input-number v-model:value="bits" min="256" max="16384" step="8" />
</n-form-item>
</div>
</div>
</div>
<div>
<n-form-item label="User Name :" label-placement="left">
<n-input
v-model:value="username"
type="text"
placeholder="User Name"
/>
</n-form-item>
<n-form-item label="User Email :" label-placement="left">
<n-input
v-model:value="useremail"
:input-props="{ type: 'email' }"
placeholder="User Email"
/>
</n-form-item>
<n-form-item label="Passphrase :" label-placement="left">
<n-input
v-model:value="password"
type="password"
show-password-on="mousedown"
placeholder="Passphrase"
/>
</n-form-item>
<div text-center>
<c-button @click="refreshCerts">
Refresh key-pair
</c-button>
</div>
</div>
<div>
<h3>Public key</h3>
<TextareaCopyable :value="certs?.publicKey || ''" word-wrap="true" />
</div>
<div>
<h3>Private key</h3>
<TextareaCopyable :value="certs?.privateKey || ''" word-wrap="true" />
</div>
<div>
<h3>Revocation Certificate</h3>
<TextareaCopyable :value="certs?.revocationCertificate || ''" word-wrap="true" />
</div>
</div>
</template>