mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 06:40:20 +03:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa0f705a63 |
No files matched your search
Vendored
+3
-1
@@ -135,6 +135,8 @@ declare module '@vue/runtime-core' {
|
||||
NH1: typeof import('naive-ui')['NH1']
|
||||
NH3: typeof import('naive-ui')['NH3']
|
||||
NIcon: typeof import('naive-ui')['NIcon']
|
||||
NInput: typeof import('naive-ui')['NInput']
|
||||
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||
NLayout: typeof import('naive-ui')['NLayout']
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
@@ -145,7 +147,7 @@ declare module '@vue/runtime-core' {
|
||||
PdfSignatureChecker: typeof import('./src/tools/pdf-signature-checker/pdf-signature-checker.vue')['default']
|
||||
PdfSignatureDetails: typeof import('./src/tools/pdf-signature-checker/components/pdf-signature-details.vue')['default']
|
||||
PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default']
|
||||
PgpEncryption: typeof import('./src/tools/pgp-encryption/pgp-encryption.vue')['default']
|
||||
PgpKeygen: typeof import('./src/tools/pgp-keygen/pgp-keygen.vue')['default']
|
||||
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
|
||||
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default']
|
||||
RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default']
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type Ref, ref, watchEffect } from 'vue';
|
||||
|
||||
export { computedCatch, computedCatchAsync };
|
||||
export { computedCatch };
|
||||
|
||||
function computedCatch<T, D>(getter: () => T, { defaultValue }: { defaultValue: D; defaultErrorMessage?: string }): [Ref<T | D>, Ref<string | undefined>];
|
||||
function computedCatch<T, D>(getter: () => T, { defaultValue, defaultErrorMessage = 'Unknown error' }: { defaultValue?: D; defaultErrorMessage?: string } = {}) {
|
||||
@@ -20,22 +20,3 @@ function computedCatch<T, D>(getter: () => T, { defaultValue, defaultErrorMessag
|
||||
|
||||
return [value, error] as const;
|
||||
}
|
||||
|
||||
function computedCatchAsync<T, D>(getterAsync: () => Promise<T>, { defaultValue }: { defaultValue: D; defaultErrorMessage?: string }): [Ref<T | D>, Ref<string | undefined>];
|
||||
function computedCatchAsync<T, D>(getterAsync: () => Promise<T>, { defaultValue, defaultErrorMessage = 'Unknown error' }: { defaultValue?: D; defaultErrorMessage?: string } = {}) {
|
||||
const error = ref<string | undefined>();
|
||||
const value = ref<T | D | undefined>();
|
||||
|
||||
watchEffect(async () => {
|
||||
try {
|
||||
error.value = undefined;
|
||||
value.value = await getterAsync();
|
||||
}
|
||||
catch (err) {
|
||||
error.value = err instanceof Error ? err.message : err?.toString() ?? defaultErrorMessage;
|
||||
value.value = defaultValue;
|
||||
}
|
||||
});
|
||||
|
||||
return [value, error] as const;
|
||||
}
|
||||
+2
-2
@@ -6,7 +6,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
import { tool as textToUnicode } from './text-to-unicode';
|
||||
import { tool as safelinkDecoder } from './safelink-decoder';
|
||||
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';
|
||||
@@ -98,7 +98,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
rsaKeyPairGenerator,
|
||||
passwordStrengthAnalyser,
|
||||
pdfSignatureChecker,
|
||||
pgpEncryption,
|
||||
pgpKeygen,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Lock } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'PGP encryption',
|
||||
path: '/pgp-encryption',
|
||||
description: 'Encrypt and decrypt text clear text using PGP Keys.',
|
||||
keywords: ['pgp', 'openpgp', 'encryption', 'cypher', 'encipher', 'crypt', 'decrypt'],
|
||||
component: () => import('./pgp-encryption.vue'),
|
||||
icon: Lock,
|
||||
createdAt: new Date('2024-04-20'),
|
||||
});
|
||||
@@ -1,194 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import * as openpgp from 'openpgp';
|
||||
import { computedCatchAsync } from '@/composable/computed/catchedComputed';
|
||||
|
||||
const cryptInput = ref('');
|
||||
const cryptPublicKey = ref('');
|
||||
const cryptPrivateKey = ref('');
|
||||
const cryptPrivateKeyPassphrase = ref('');
|
||||
const [cryptOutput, cryptError] = computedCatchAsync(async () => {
|
||||
const publicKeyArmored = cryptPublicKey.value;
|
||||
const privateKeyArmored = cryptPrivateKey.value;
|
||||
const passphrase = cryptPrivateKeyPassphrase.value;
|
||||
const text = cryptInput.value;
|
||||
|
||||
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
||||
|
||||
const privateKey = privateKeyArmored !== ''
|
||||
? (passphrase !== ''
|
||||
? await openpgp.decryptKey({
|
||||
privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }),
|
||||
passphrase,
|
||||
})
|
||||
: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }))
|
||||
: undefined;
|
||||
|
||||
return await openpgp.encrypt({
|
||||
message: await openpgp.createMessage({ text }),
|
||||
encryptionKeys: publicKey,
|
||||
signingKeys: privateKey,
|
||||
});
|
||||
}, {
|
||||
defaultValue: '',
|
||||
defaultErrorMessage: 'Unable to encrypt your text',
|
||||
});
|
||||
|
||||
const decryptInput = ref('');
|
||||
const decryptPublicKey = ref('');
|
||||
const decryptPrivateKey = ref('');
|
||||
const decryptPrivateKeyPassphrase = ref('');
|
||||
const [decryptOutput, decryptError] = computedCatchAsync(async () => {
|
||||
const publicKeyArmored = decryptPublicKey.value;
|
||||
const privateKeyArmored = decryptPrivateKey.value;
|
||||
const passphrase = decryptPrivateKeyPassphrase.value;
|
||||
const encrypted = decryptInput.value;
|
||||
|
||||
const publicKey = publicKeyArmored !== '' ? await openpgp.readKey({ armoredKey: publicKeyArmored }) : undefined;
|
||||
|
||||
const privateKey = passphrase !== ''
|
||||
? await openpgp.decryptKey({
|
||||
privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }),
|
||||
passphrase,
|
||||
})
|
||||
: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored });
|
||||
|
||||
const message = await openpgp.readMessage({
|
||||
armoredMessage: encrypted, // parse armored message
|
||||
});
|
||||
const { data: decrypted, signatures } = await openpgp.decrypt({
|
||||
message,
|
||||
verificationKeys: publicKey, // optional
|
||||
decryptionKeys: privateKey,
|
||||
});
|
||||
if (signatures.length > 0) {
|
||||
try {
|
||||
await signatures[0].verified; // throws on invalid signature
|
||||
}
|
||||
catch (e: any) {
|
||||
return {
|
||||
decryptedText: decrypted,
|
||||
signatureError: `Signature could not be verified: ${e.toString()}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
return {
|
||||
decryptedText: decrypted,
|
||||
signatureError: '',
|
||||
};
|
||||
}, {
|
||||
defaultValue: { decryptedText: '', signatureError: '' },
|
||||
defaultErrorMessage: 'Unable to encrypt your text',
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card title="Encrypt">
|
||||
<div>
|
||||
<c-input-text
|
||||
v-model:value="cryptInput"
|
||||
label="Your text:"
|
||||
placeholder="The string to encrypt"
|
||||
rows="4"
|
||||
multiline raw-text monospace autosize flex-1
|
||||
/>
|
||||
<div flex flex-1 flex-col gap-2>
|
||||
<c-input-text
|
||||
v-model:value="cryptPublicKey"
|
||||
label="Target public key:"
|
||||
placeholder="Target public key"
|
||||
rows="5"
|
||||
multiline raw-text monospace autosize flex-1
|
||||
/>
|
||||
|
||||
<details>
|
||||
<summary>Signing private key (optional)</summary>
|
||||
<c-input-text
|
||||
v-model:value="cryptPrivateKey"
|
||||
label="Your private key:"
|
||||
placeholder="The private key to use to sign message"
|
||||
rows="5"
|
||||
multiline raw-text monospace autosize flex-1
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="cryptPrivateKeyPassphrase"
|
||||
label="Your private key password:" clearable raw-text
|
||||
/>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<c-alert
|
||||
v-if="cryptError && cryptPublicKey !== ''"
|
||||
type="error" mt-12 title="Error while encrypting"
|
||||
>
|
||||
{{ cryptError }}
|
||||
</c-alert>
|
||||
|
||||
<n-form-item label="Your text encrypted:" mt-3>
|
||||
<TextareaCopyable
|
||||
:value="cryptOutput || ''"
|
||||
rows="3"
|
||||
placeholder="Your string encrypted"
|
||||
multiline monospace readonly autosize mt-5
|
||||
/>
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Decrypt">
|
||||
<div>
|
||||
<c-input-text
|
||||
v-model:value="decryptInput"
|
||||
label="Your PGP Message to decrypt:"
|
||||
placeholder="The string to decrypt"
|
||||
rows="4"
|
||||
multiline raw-text monospace autosize flex-1
|
||||
/>
|
||||
<div flex flex-1 flex-col gap-2>
|
||||
<c-input-text
|
||||
v-model:value="decryptPrivateKey"
|
||||
label="Your private key:"
|
||||
placeholder="The private key to use to decrypt message"
|
||||
rows="5"
|
||||
multiline raw-text monospace autosize flex-1
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="decryptPrivateKeyPassphrase"
|
||||
label="Your private key password:" clearable raw-text
|
||||
/>
|
||||
|
||||
<details>
|
||||
<summary>Signing public key (optional)</summary>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="decryptPublicKey"
|
||||
label="Sender public key:"
|
||||
placeholder="Sender public key"
|
||||
rows="5"
|
||||
multiline raw-text monospace autosize flex-1
|
||||
/>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<c-alert v-if="decryptError && decryptPrivateKey !== ''" type="error" mt-3 title="Error while decrypting">
|
||||
{{ decryptError }}
|
||||
</c-alert>
|
||||
|
||||
<c-alert v-if="decryptOutput?.signatureError !== ''" type="error" mt-3 title="Signature verification">
|
||||
{{ decryptOutput?.signatureError }}
|
||||
</c-alert>
|
||||
|
||||
<n-form-item label="Your text decrypted:" mt-3>
|
||||
<TextareaCopyable
|
||||
:value="decryptOutput?.decryptedText || ''"
|
||||
rows="3"
|
||||
placeholder="Your string decrypted"
|
||||
multiline monospace readonly autosize mt-5
|
||||
/>
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -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'),
|
||||
});
|
||||
@@ -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>
|
||||
Reference in new issue
Block a user