diff --git a/packages/api/src/@core/@core-services/encryption/encryption.service.ts b/packages/api/src/@core/@core-services/encryption/encryption.service.ts index c5910075d..25be858af 100644 --- a/packages/api/src/@core/@core-services/encryption/encryption.service.ts +++ b/packages/api/src/@core/@core-services/encryption/encryption.service.ts @@ -9,11 +9,12 @@ export class EncryptionService { private iv = crypto.randomBytes(16); constructor(private env: EnvironmentService, private logger: LoggerService) { - this.secretKey = this.env.getCryptoKey(); + this.secretKey = process.env.ENCRYPT_CRYPTO_SECRET_KEY; } encrypt(data: string): string { try { + if (!data) throw new Error('Cant encrypt empty string'); const cipher = crypto.createCipheriv( 'aes-256-cbc', Buffer.from(this.secretKey, 'utf-8'), diff --git a/packages/api/src/@core/connections-strategies/connections-strategies.service.ts b/packages/api/src/@core/connections-strategies/connections-strategies.service.ts index 8bd71ef00..a97324607 100644 --- a/packages/api/src/@core/connections-strategies/connections-strategies.service.ts +++ b/packages/api/src/@core/connections-strategies/connections-strategies.service.ts @@ -90,6 +90,7 @@ export class ConnectionsStrategiesService { for (let i = 0; i < attributes.length; i++) { const attribute_slug = attributes[i]; const value = values[i]; + const encrypted_value = this.crypto.encrypt(value); //create all attributes (for oauth => client_id, client_secret) const attribute_ = await this.prisma.cs_attributes.create({ data: { @@ -102,7 +103,7 @@ export class ConnectionsStrategiesService { const value_ = await this.prisma.cs_values.create({ data: { id_cs_value: uuidv4(), - value: this.crypto.encrypt(value), + value: encrypted_value, id_cs_attribute: attribute_.id_cs_attribute, }, });