Introduce useCrypto composable for encryption and decryption with RSA
This commit is contained in:
18
src/composables/useCrypto.ts
Normal file
18
src/composables/useCrypto.ts
Normal file
@@ -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,
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user