Compare commits

..
Author SHA1 Message Date
sharevb a748499413 Merge branch 'main' into feat/mime-converter 2024-03-11 22:31:44 +01:00
sharevb df7cc7cccc feat(new tool): MIME Encoder/Decoder
Fix #408
2024-03-11 22:22:41 +01:00
16 changed files with 758 additions and 271 deletions

No files matched your search

+1 -1
View File
@@ -15,7 +15,7 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: 20
node-version: 16
cache: 'pnpm'
- name: Install dependencies
+1 -1
View File
@@ -18,7 +18,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 20
node-version: 16
cache: 'pnpm'
- name: Get Playwright version
+1 -9
View File
@@ -125,26 +125,20 @@ declare module '@vue/runtime-core' {
MenuIconItem: typeof import('./src/components/MenuIconItem.vue')['default']
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
MimeConverter: typeof import('./src/tools/mime-converter/mime-converter.vue')['default']
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
NCode: typeof import('naive-ui')['NCode']
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDivider: typeof import('naive-ui')['NDivider']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NFormItem: typeof import('naive-ui')['NFormItem']
NGi: typeof import('naive-ui')['NGi']
NGrid: typeof import('naive-ui')['NGrid']
NH1: typeof import('naive-ui')['NH1']
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
NInputNumber: typeof import('naive-ui')['NInputNumber']
NLabel: typeof import('naive-ui')['NLabel']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSpin: typeof import('naive-ui')['NSpin']
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
@@ -158,9 +152,7 @@ declare module '@vue/runtime-core' {
RomanNumeralConverter: typeof import('./src/tools/roman-numeral-converter/roman-numeral-converter.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
RsaEncryption: typeof import('./src/tools/rsa-encryption/rsa-encryption.vue')['default']
RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default']
SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default']
SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default']
SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default']
SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default']
+3 -1
View File
@@ -42,6 +42,7 @@
"@tiptap/starter-kit": "2.1.6",
"@tiptap/vue-3": "2.0.3",
"@types/figlet": "^1.5.8",
"@types/libmime": "^5.0.3",
"@vicons/material": "^0.12.0",
"@vicons/tabler": "^0.12.0",
"@vueuse/core": "^10.3.0",
@@ -64,9 +65,9 @@
"highlight.js": "^11.7.0",
"iarna-toml-esm": "^3.0.5",
"ibantools": "^4.3.3",
"js-base64": "^3.7.7",
"json5": "^2.2.3",
"jwt-decode": "^3.1.2",
"libmime": "^5.3.4",
"libphonenumber-js": "^1.10.28",
"lodash": "^4.17.21",
"marked": "^10.0.0",
@@ -132,6 +133,7 @@
"unplugin-icons": "^0.17.0",
"unplugin-vue-components": "^0.25.0",
"vite": "^4.4.9",
"vite-plugin-node-polyfills": "^0.21.0",
"vite-plugin-pwa": "^0.16.0",
"vite-plugin-vue-markdown": "^0.23.5",
"vite-svg-loader": "^4.0.0",
+2 -2
View File
@@ -9,7 +9,7 @@ const useWebServer = process.env.NO_WEB_SERVER !== 'true';
*/
export default defineConfig({
testDir: './src',
testMatch: /\.e2e\.(spec\.)?ts$/,
testMatch: /.*\.e2e\.(spec\.)?ts/,
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
@@ -57,7 +57,7 @@ export default defineConfig({
&& {
webServer: {
command: 'npm run preview',
url: 'http://localhost:5050',
url: 'http://127.0.0.1:5050',
reuseExistingServer: !isCI,
},
}
+660 -13
View File
File diff suppressed because it is too large. Load diff
+1 -20
View File
@@ -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;
}
+1 -1
View File
@@ -28,7 +28,7 @@ const compareMatch = computed(() => compareSync(compareString.value, compareHash
mb-2
/>
<n-form-item label="Salt count: " label-placement="left" label-width="120">
<n-input-number v-model:value="saltCount" placeholder="Salt rounds..." :max="100" :min="0" w-full />
<n-input-number v-model:value="saltCount" placeholder="Salt rounds..." :max="10" :min="0" w-full />
</n-form-item>
<c-input-text :value="hashed" readonly text-center />
+3 -15
View File
@@ -5,8 +5,8 @@ import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as asciiTextDrawer } from './ascii-text-drawer';
import { tool as textToUnicode } from './text-to-unicode';
import { tool as mimeConverter } from './mime-converter';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as rsaEncryption } from './rsa-encryption';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -86,20 +86,7 @@ import { tool as yamlViewer } from './yaml-viewer';
export const toolsByCategory: ToolCategory[] = [
{
name: 'Crypto',
components: [
tokenGenerator,
hashText,
bcrypt,
uuidGenerator,
ulidGenerator,
cypher,
bip39,
hmacGenerator,
rsaKeyPairGenerator,
passwordStrengthAnalyser,
pdfSignatureChecker,
rsaEncryption,
],
components: [tokenGenerator, hashText, bcrypt, uuidGenerator, ulidGenerator, cypher, bip39, hmacGenerator, rsaKeyPairGenerator, passwordStrengthAnalyser, pdfSignatureChecker],
},
{
name: 'Converter',
@@ -121,6 +108,7 @@ export const toolsByCategory: ToolCategory[] = [
listConverter,
tomlToJson,
tomlToYaml,
mimeConverter,
],
},
{
@@ -11,9 +11,6 @@ describe('integer-base-converter', () => {
expect(convertBase({ value: '10100101', fromBase: 2, toBase: 16 })).toEqual('a5');
expect(convertBase({ value: '192654', fromBase: 10, toBase: 8 })).toEqual('570216');
expect(convertBase({ value: 'zz', fromBase: 64, toBase: 10 })).toEqual('2275');
expect(convertBase({ value: '42540766411283223938465490632011909384', fromBase: 10, toBase: 10 })).toEqual('42540766411283223938465490632011909384');
expect(convertBase({ value: '42540766411283223938465490632011909384', fromBase: 10, toBase: 16 })).toEqual('20010db8000085a300000000ac1f8908');
expect(convertBase({ value: '20010db8000085a300000000ac1f8908', fromBase: 16, toBase: 10 })).toEqual('42540766411283223938465490632011909384');
});
});
});
@@ -5,16 +5,16 @@ export function convertBase({ value, fromBase, toBase }: { value: string; fromBa
let decValue = value
.split('')
.reverse()
.reduce((carry: bigint, digit: string, index: number) => {
.reduce((carry: number, digit: string, index: number) => {
if (!fromRange.includes(digit)) {
throw new Error(`Invalid digit "${digit}" for base ${fromBase}.`);
}
return (carry += BigInt(fromRange.indexOf(digit)) * BigInt(fromBase) ** BigInt(index));
}, 0n);
return (carry += fromRange.indexOf(digit) * fromBase ** index);
}, 0);
let newValue = '';
while (decValue > 0) {
newValue = toRange[Number(decValue % BigInt(toBase))] + newValue;
decValue = (decValue - (decValue % BigInt(toBase))) / BigInt(toBase);
newValue = toRange[decValue % toBase] + newValue;
decValue = (decValue - (decValue % toBase)) / toBase;
}
return newValue || '0';
}
+12
View File
@@ -0,0 +1,12 @@
import { Mail } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'MIME Encoding Converter',
path: '/mime-converter',
description: 'Convert from/to MIME Encoded-Word format (Mail Subject)',
keywords: ['mime', 'converter', 'subject', 'rfc2047', 'rfc1341', 'rfc2045'],
component: () => import('./mime-converter.vue'),
icon: Mail,
createdAt: new Date('2024-03-09'),
});
@@ -0,0 +1,66 @@
<script setup lang="ts">
import libmime from 'libmime';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
import { withDefaultOnError } from '@/utils/defaults';
const encodedInput = ref('');
const decodedOutput = computed(() => withDefaultOnError(() => libmime.decodeWords(encodedInput.value), '# invalid encoded value'));
const rawInput = ref('');
const encodedQOutput = computed(() => withDefaultOnError(() => libmime.encodeWord(rawInput.value, 'Q'), ''));
const encodedBOutput = computed(() => withDefaultOnError(() => libmime.encodeWord(rawInput.value, 'B'), ''));
</script>
<template>
<div style="max-width: 600px;">
<c-card title="Encode string in Encoded-Word format">
<c-input-text
v-model:value="rawInput"
multiline
placeholder="Put your string here..."
rows="5"
label="String to encode"
raw-text
mb-5
/>
<div>
<h3>Quotted Printable encoded string</h3>
<TextareaCopyable
:value="encodedQOutput"
placeholder="The Quotted Printable encoded version of your string will be here"
mb-5
/>
</div>
<div>
<h3>Base64 encoded string</h3>
<TextareaCopyable
:value="encodedBOutput"
placeholder="The Base64 encoded version of your string will be here"
mb-5
/>
</div>
</c-card>
<c-card title="Decode string in Encoded-Word format">
<c-input-text
v-model:value="encodedInput"
multiline
placeholder="Your encoded string..."
rows="5"
label="Encoded string to decode"
mb-5
/>
<div>
<h3>Decoded string</h3>
<TextareaCopyable
v-model:value="decodedOutput"
placeholder="The decoded string will be here"
mb-5
/>
</div>
</c-card>
</div>
</template>
-12
View File
@@ -1,12 +0,0 @@
import { Lock } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'RSA encryption',
path: '/rsa-encryption',
description: 'Encrypt and decrypt text clear text using RSA Keys.',
keywords: ['rsa', 'encryption', 'cypher', 'encipher', 'crypt', 'decrypt'],
component: () => import('./rsa-encryption.vue'),
icon: Lock,
createdAt: new Date('2024-04-20'),
});
-188
View File
@@ -1,188 +0,0 @@
<script setup lang="ts">
import { md, pki } from 'node-forge';
import { Base64 } from 'js-base64';
import { computedCatchAsync } from '@/composable/computed/catchedComputed';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const schemes = [
{ value: 'RSAES-PKCS1-V1_5', label: 'RSAES PKCS#1 v1.5' },
{ value: 'RSAES-OAEP', label: 'RSAES-OAEP' },
{ value: 'RSAES-OAEP/SHA-256', label: 'RSAES-OAEP/SHA-256' },
{ value: 'RSAES-OAEP/SHA-256/MGF1-SHA-1', label: 'RSAES-OAEP/SHA-256/MGF1-SHA-1 (RSA/ECB/OAEPWithSHA-256AndMGF1Padding)' },
];
const cryptInput = ref('');
const cryptScheme = ref('RSAES-PKCS1-V1_5');
const cryptPublicKey = ref('');
const [cryptOutput, cryptError] = computedCatchAsync(async () => {
const publicKeyPEM = cryptPublicKey.value;
const text = cryptInput.value;
const scheme = cryptScheme.value;
const publicKey = pki.publicKeyFromPem(publicKeyPEM);
let encrypted;
if (scheme === 'RSAES-PKCS1-V1_5') {
// encrypt data with a public key using RSAES PKCS#1 v1.5
encrypted = publicKey.encrypt(text, 'RSAES-PKCS1-V1_5');
}
else if (scheme === 'RSAES-OAEP') {
// encrypt data with a public key using RSAES-OAEP
encrypted = publicKey.encrypt(text, 'RSA-OAEP');
}
else if (scheme === 'RSAES-OAEP/SHA-256') {
// encrypt data with a public key using RSAES-OAEP/SHA-256
encrypted = publicKey.encrypt(text, 'RSA-OAEP', {
md: md.sha256.create(),
});
}
else if (scheme === 'RSAES-OAEP/SHA-256/MGF1-SHA-1') {
// encrypt data with a public key using RSAES-OAEP/SHA-256/MGF1-SHA-1
// compatible with Java's RSA/ECB/OAEPWithSHA-256AndMGF1Padding
encrypted = publicKey.encrypt(text, 'RSA-OAEP', {
md: md.sha256.create(),
mgf1: {
md: md.sha1.create(),
},
});
}
return Base64.encode(encrypted || '');
}, {
defaultValue: '',
defaultErrorMessage: 'Unable to encrypt your text',
});
const decryptInput = ref('');
const decryptScheme = ref('RSAES-PKCS1-V1_5');
const decryptPrivateKey = ref('');
const decryptPrivateKeyPassphrase = ref('');
const [decryptOutput, decryptError] = computedCatchAsync(async () => {
const privateKeyPEM = decryptPrivateKey.value;
const passphrase = decryptPrivateKeyPassphrase.value;
const encrypted = Base64.decode(decryptInput.value);
const scheme = decryptScheme.value;
const privateKey = pki.decryptRsaPrivateKey(privateKeyPEM, passphrase);
let decrypted;
if (scheme === 'RSAES-PKCS1-V1_5') {
// decrypt data with a private key using RSAES PKCS#1 v1.5
decrypted = privateKey.decrypt(encrypted, 'RSAES-PKCS1-V1_5');
}
else if (scheme === 'RSAES-OAEP') {
// decrypt data with a private key using RSAES-OAEP
decrypted = privateKey.decrypt(encrypted, 'RSA-OAEP');
}
else if (scheme === 'RSAES-OAEP/SHA-256') {
// decrypt data with a private key using RSAES-OAEP/SHA-256
decrypted = privateKey.decrypt(encrypted, 'RSA-OAEP', {
md: md.sha256.create(),
});
}
else if (scheme === 'RSAES-OAEP/SHA-256/MGF1-SHA-1') {
// decrypt data with a private key using RSAES-OAEP/SHA-256/MGF1-SHA-1
// compatible with Java's RSA/ECB/OAEPWithSHA-256AndMGF1Padding
decrypted = privateKey.decrypt(encrypted, 'RSA-OAEP', {
md: md.sha256.create(),
mgf1: {
md: md.sha1.create(),
},
});
}
return decrypted;
}, {
defaultValue: '',
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
/>
<c-select
v-model:value="cryptScheme"
label="Scheme:"
:options="schemes"
placeholder="Select the encryption scheme"
/>
<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
/>
</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
/>
<c-select
v-model:value="decryptScheme"
label="Scheme:"
:options="schemes"
placeholder="Select the encryption scheme"
/>
<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
/>
</div>
</div>
<c-alert v-if="decryptError && decryptPrivateKey !== ''" type="error" mt-12 title="Error while decrypting">
{{ decryptError }}
</c-alert>
<n-form-item label="Your text decrypted:" mt-3>
<TextareaCopyable
:value="decryptOutput || ''"
rows="3"
placeholder="Your string decrypted"
multiline monospace readonly autosize mt-5
/>
</n-form-item>
</c-card>
</div>
</template>
+2
View File
@@ -11,6 +11,7 @@ import Icons from 'unplugin-icons/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { VitePWA } from 'vite-plugin-pwa';
import markdown from 'vite-plugin-vue-markdown';
import svgLoader from 'vite-svg-loader';
@@ -97,6 +98,7 @@ export default defineConfig({
resolvers: [NaiveUiResolver(), IconsResolver({ prefix: 'icon' })],
}),
Unocss(),
nodePolyfills(),
],
base: baseUrl,
resolve: {