Giter VIP home page Giter VIP logo

node-mysql-aes's Introduction

Requirements and Recommendations

  • Nodejs v18.6.0 (untested other versions)
  • NPM 8.13.2
  • MariaDB 10.8.3, for Linux (x86_64)

What Does This Do?

This encrypts and decrypts columns stored in database tables in NodeJS applications. by encrypting data as it is stored in the model attributes and decrypting data as it is recalled from the model attributes.

Note: Encrypted values are usually longer than plain text values. Sometimes much longer. You may find that the column widths in your database tables need to be extended to store the encrypted values.

Data APP

Features

Data DB

Features

Configuration

Add APP_KEY as environment variable to .env file

.env

APP_KEY = yourkey

Encryption

Node JS

To encrypt before insert/update into database, use helper function from utils/crypt.js. Ex

import { encrypt } from '@/utils/crypt.js'
...
...
const first_name = req.body.first_name
const query = `INSERT INTO user SET first_name = ${encrypt(first_name)}`

SQL Query

INSERT INTO user SET first_name = HEX(AES_ENCRYPT('Test Nama', 'app_key') ), last_name = HEX(AES_ENCRYPT('Last Name', 'app_key') ), phone = HEX(AES_ENCRYPT('0811111111', 'app_key') ), email = HEX(AES_ENCRYPT('[email protected]', 'app_key') ), comments = 'comment';

Decrypt

Node JS

To get decrypted value from encrypted data, use helper function from utils/crypt.js. Ex

import { decrypt } from '@/utils/crypt.js'
...
...
const query = `SELECT *, ${decrypt('first_name')} FROM user`

SQL Query

SELECT *, AES_DECRYPT( UNHEX(first_name), 'app_key' ) as first_name FROM user;

Use decrypt in filter

SELECT *, AES_DECRYPT( UNHEX(first_name), 'app_key' ) as first_name FROM user WHERE AES_DECRYPT(UNHEX(first_name), 'app_key') like '%Test%';

node-mysql-aes's People

Contributors

rizkylab avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.