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/BaseUploadInput.vue b/src/renderer/components/BaseUploadInput.vue index b2076b72..89d91790 100644 --- a/src/renderer/components/BaseUploadInput.vue +++ b/src/renderer/components/BaseUploadInput.vue @@ -16,6 +16,7 @@ :id="`id_${id}`" class="file-uploader-input" type="file" + :accept="accept" @change="$emit('change', $event)" > @@ -33,6 +34,10 @@ defineProps({ default: 'Browse', type: String }, + accept: { + default: '', + type: String + }, modelValue: { default: '', type: String 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" >