Skip to content

Instantly share code, notes, and snippets.

@antoniosanct
Last active April 25, 2022 19:54
Show Gist options
  • Save antoniosanct/10cd80986e586df6988113ffbdc4d123 to your computer and use it in GitHub Desktop.
Save antoniosanct/10cd80986e586df6988113ffbdc4d123 to your computer and use it in GitHub Desktop.
Create Sequelize connection using an AES encrypted password
import Utf8 from 'crypto-js/enc-utf8.js';
import AES from 'crypto-js/aes.js';
const secretKey = 'gist-sequelize'
export function decrypt(ciphertext) {
return AES.decrypt(ciphertext, secretKey).toString(Utf8);
}
import Sequelize from 'sequelize';
import { ENV } from './env.js'
import { decrypt } from './crypto.js';
export const sequelize = new Sequelize(ENV.db_database, ENV.db_username, decrypt(ENV.db_password), {
host: ENV.db_host,
dialect: ENV.db_dialect,
logging: false
});
export const ENV = {
db_host: '<db_host>',
db_dialect: '<db_dialect>',
db_database: '<db_database>',
db_username: '<db_username>',
db_password: '<aes_encrypted_with_secretKey_db_password>'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment