From f5b86e59e7e41bbbe1555ec8a85ec1f849e8271d Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Thu, 17 Aug 2023 13:48:55 +0200 Subject: [PATCH 1/2] feat: ability to export connections --- src/common/libs/encrypter.ts | 31 ++ .../components/ModalConnectionAppearance.vue | 2 +- src/renderer/components/ModalExportSchema.vue | 4 +- src/renderer/components/ModalSettings.vue | 23 +- src/renderer/components/ModalSettingsData.vue | 84 +++++ .../components/ModalSettingsDataExport.vue | 327 ++++++++++++++++++ src/renderer/i18n/ca-ES.ts | 1 - src/renderer/i18n/en-US.ts | 13 +- src/renderer/i18n/fr-FR.ts | 1 - src/renderer/i18n/pt-BR.ts | 1 - src/renderer/libs/unproxify.ts | 2 +- src/renderer/scss/themes/dark-theme.scss | 10 +- 12 files changed, 485 insertions(+), 14 deletions(-) create mode 100644 src/common/libs/encrypter.ts create mode 100644 src/renderer/components/ModalSettingsData.vue create mode 100644 src/renderer/components/ModalSettingsDataExport.vue diff --git a/src/common/libs/encrypter.ts b/src/common/libs/encrypter.ts new file mode 100644 index 00000000..1d608d81 --- /dev/null +++ b/src/common/libs/encrypter.ts @@ -0,0 +1,31 @@ +import * as crypto from 'crypto'; + +const algorithm = 'aes-256-gcm'; + +function encrypt (text: string, password: string) { + const iv = crypto.randomBytes(16); + const key = crypto.scryptSync(password, 'antares', 32); + const cipher = crypto.createCipheriv(algorithm, key, iv); + const encrypted = Buffer.concat([cipher.update(text), cipher.final()]); + const authTag = cipher.getAuthTag(); + + return { + iv: iv.toString('hex'), + authTag: authTag.toString('hex'), + content: encrypted.toString('hex') + }; +} + +function decrypt (hash: { iv: string; content: string; authTag: string }, password: string) { + const key = crypto.scryptSync(password, 'antares', 32); + const decipher = crypto.createDecipheriv(algorithm, key, Buffer.from(hash.iv, 'hex')); + decipher.setAuthTag(Buffer.from(hash.authTag, 'hex')); + const decrpyted = decipher.update(hash.content, 'hex', 'utf8') + decipher.final('utf8'); + + return decrpyted; +} + +export { + encrypt, + decrypt +}; diff --git a/src/renderer/components/ModalConnectionAppearance.vue b/src/renderer/components/ModalConnectionAppearance.vue index 02ac0241..52ddd43c 100644 --- a/src/renderer/components/ModalConnectionAppearance.vue +++ b/src/renderer/components/ModalConnectionAppearance.vue @@ -7,7 +7,7 @@ diff --git a/src/renderer/components/ModalExportSchema.vue b/src/renderer/components/ModalExportSchema.vue index 14072bb3..c91313c3 100644 --- a/src/renderer/components/ModalExportSchema.vue +++ b/src/renderer/components/ModalExportSchema.vue @@ -26,7 +26,7 @@ type="text" required readonly - :placeholder="t('database.schemaName')" + @click.prevent="openPathDialog" >