Last active
April 25, 2022 19:54
-
-
Save antoniosanct/10cd80986e586df6988113ffbdc4d123 to your computer and use it in GitHub Desktop.
Create Sequelize connection using an AES encrypted password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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