From 951905b33c47ba245ece95487dee0b345a088055 Mon Sep 17 00:00:00 2001 From: Paul Spenke Date: Sat, 21 Feb 2026 17:19:03 +0100 Subject: [PATCH] Introduce `useCrypto` composable for encryption and decryption with RSA --- src/composables/useCrypto.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/composables/useCrypto.ts diff --git a/src/composables/useCrypto.ts b/src/composables/useCrypto.ts new file mode 100644 index 0000000..5ff2dad --- /dev/null +++ b/src/composables/useCrypto.ts @@ -0,0 +1,18 @@ +import { JSEncrypt } from 'jsencrypt'; +const secret = import.meta.env.VITE_SECRET; + +if (!secret) { + throw new Error('VITE_SECRET is not set'); +} +const crypt = new JSEncrypt(); +crypt.setPrivateKey(secret); + +export function useCrypto() { + const encrypt = (value: string) => crypt.encrypt(value); + const decrypt = (value: string) => crypt.decrypt(value); + + return { + encrypt, + decrypt, + }; +}