From 97a2a11613705bf955702c360ecb311ccdf8b248 Mon Sep 17 00:00:00 2001 From: sharevb Date: Sun, 28 Apr 2024 12:56:44 +0200 Subject: [PATCH] feat(new tool): RSA Encryption Fix #945 --- components.d.ts | 2 + package.json | 1 + pnpm-lock.yaml | 20 ++- src/composable/computed/catchedComputed.ts | 21 ++- src/tools/index.ts | 16 +- src/tools/rsa-encryption/index.ts | 12 ++ src/tools/rsa-encryption/rsa-encryption.vue | 188 ++++++++++++++++++++ 7 files changed, 252 insertions(+), 8 deletions(-) create mode 100644 src/tools/rsa-encryption/index.ts create mode 100644 src/tools/rsa-encryption/rsa-encryption.vue diff --git a/components.d.ts b/components.d.ts index e31119b3..fd8f4435 100644 --- a/components.d.ts +++ b/components.d.ts @@ -158,7 +158,9 @@ 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'] diff --git a/package.json b/package.json index fd6c02e6..132a64cb 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "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", "libphonenumber-js": "^1.10.28", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd6c38c9..b2b0f182 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -92,6 +92,9 @@ dependencies: ibantools: specifier: ^4.3.3 version: 4.3.3 + js-base64: + specifier: ^3.7.7 + version: 3.7.7 json5: specifier: ^2.2.3 version: 2.2.3 @@ -3351,7 +3354,7 @@ packages: dependencies: '@unhead/dom': 0.5.1 '@unhead/schema': 0.5.1 - '@vueuse/shared': 10.7.2(vue@3.3.4) + '@vueuse/shared': 10.9.0(vue@3.3.4) unhead: 0.5.1 vue: 3.3.4 transitivePeerDependencies: @@ -3993,10 +3996,10 @@ packages: - vue dev: false - /@vueuse/shared@10.7.2(vue@3.3.4): - resolution: {integrity: sha512-qFbXoxS44pi2FkgFjPvF4h7c9oMDutpyBdcJdMYIMg9XyXli2meFMuaKn+UMgsClo//Th6+beeCgqweT/79BVA==} + /@vueuse/shared@10.9.0(vue@3.3.4): + resolution: {integrity: sha512-Uud2IWncmAfJvRaFYzv5OHDli+FbOzxiVEQdLCKQKLyhz94PIyFC3CHcH7EDMwIn8NPtD06+PNbC/PiO0LGLtw==} dependencies: - vue-demi: 0.14.6(vue@3.3.4) + vue-demi: 0.14.7(vue@3.3.4) transitivePeerDependencies: - '@vue/composition-api' - vue @@ -6472,6 +6475,10 @@ packages: hasBin: true dev: true + /js-base64@3.7.7: + resolution: {integrity: sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==} + dev: false + /js-beautify@1.14.6: resolution: {integrity: sha512-GfofQY5zDp+cuHc+gsEXKPpNw2KbPddreEo35O6jT6i0RVK6LhsoYBhq5TvK4/n74wnA0QbK8gGd+jUZwTMKJw==} engines: {node: '>=10'} @@ -9151,8 +9158,8 @@ packages: vue: 3.3.4 dev: false - /vue-demi@0.14.6(vue@3.3.4): - resolution: {integrity: sha512-8QA7wrYSHKaYgUxDA5ZC24w+eHm3sYCbp0EzcDwKqN3p6HqtTCGR/GVsPyZW92unff4UlcSh++lmqDWN3ZIq4w==} + /vue-demi@0.14.7(vue@3.3.4): + resolution: {integrity: sha512-EOG8KXDQNwkJILkx/gPcoL/7vH+hORoBaKgGe+6W7VFMvCYJfmF2dGbvgDroVnI8LU7/kTu8mbjRZGBU1z9NTA==} engines: {node: '>=12'} hasBin: true requiresBuild: true @@ -9442,6 +9449,7 @@ packages: /workbox-google-analytics@7.0.0: resolution: {integrity: sha512-MEYM1JTn/qiC3DbpvP2BVhyIH+dV/5BjHk756u9VbwuAhu0QHyKscTnisQuz21lfRpOwiS9z4XdqeVAKol0bzg==} + deprecated: It is not compatible with newer versions of GA starting with v4, as long as you are using GAv3 it should be ok, but the package is not longer being maintained dependencies: workbox-background-sync: 7.0.0 workbox-core: 7.0.0 diff --git a/src/composable/computed/catchedComputed.ts b/src/composable/computed/catchedComputed.ts index fd00a128..259c481e 100644 --- a/src/composable/computed/catchedComputed.ts +++ b/src/composable/computed/catchedComputed.ts @@ -1,6 +1,6 @@ import { type Ref, ref, watchEffect } from 'vue'; -export { computedCatch }; +export { computedCatch, computedCatchAsync }; function computedCatch(getter: () => T, { defaultValue }: { defaultValue: D; defaultErrorMessage?: string }): [Ref, Ref]; function computedCatch(getter: () => T, { defaultValue, defaultErrorMessage = 'Unknown error' }: { defaultValue?: D; defaultErrorMessage?: string } = {}) { @@ -20,3 +20,22 @@ function computedCatch(getter: () => T, { defaultValue, defaultErrorMessag return [value, error] as const; } + +function computedCatchAsync(getterAsync: () => Promise, { defaultValue }: { defaultValue: D; defaultErrorMessage?: string }): [Ref, Ref]; +function computedCatchAsync(getterAsync: () => Promise, { defaultValue, defaultErrorMessage = 'Unknown error' }: { defaultValue?: D; defaultErrorMessage?: string } = {}) { + const error = ref(); + const value = ref(); + + 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; +} diff --git a/src/tools/index.ts b/src/tools/index.ts index aa861c93..7b8969f6 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -6,6 +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 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'; @@ -85,7 +86,20 @@ 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], + components: [ + tokenGenerator, + hashText, + bcrypt, + uuidGenerator, + ulidGenerator, + cypher, + bip39, + hmacGenerator, + rsaKeyPairGenerator, + passwordStrengthAnalyser, + pdfSignatureChecker, + rsaEncryption, + ], }, { name: 'Converter', diff --git a/src/tools/rsa-encryption/index.ts b/src/tools/rsa-encryption/index.ts new file mode 100644 index 00000000..1380d7a9 --- /dev/null +++ b/src/tools/rsa-encryption/index.ts @@ -0,0 +1,12 @@ +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'), +}); diff --git a/src/tools/rsa-encryption/rsa-encryption.vue b/src/tools/rsa-encryption/rsa-encryption.vue new file mode 100644 index 00000000..661fe032 --- /dev/null +++ b/src/tools/rsa-encryption/rsa-encryption.vue @@ -0,0 +1,188 @@ + + +