npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sequelize-encryption

v1.0.3

Published

![Version](https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000) [![Documentation](https://img.shields.io/badge/documentation-yes-brightgreen.svg)](https://github.com/mithelan/aes-mysql-node) [![License: ''](https://img.shields.io/badg

Readme

Welcome to sequelize-encryption 👋

Version Documentation License: '' Twitter: kdmithii

sequelize-encryption is tool where you can use to encrypt and decrypt the fields same as mysql native aes_encrypt and aes_decrypt and casting and custom methods available

🏠 Homepage

Install

npm i sequelize-encryption

or

yarn add sequelize-encryption

Generate a encryption key

openssl rand -hex 16

sample-> 3c7a4eb821c141726cebd608862da861

Available methods

  1. castQuery - `CAST(AES_DECRYPT(UNHEX(tableFieldName}),'${encryptionKey}') AS CHAR(50))`

  2. customQuery - `SELECT [tableFields],CAST(AES_DECRYPT(UNHEX(tableFieldName), encryptionKey) AS CHAR(50)) 
                    aliasName FROM   tableName`

  3. encryptData - `SELECT HEX(AES_ENCRYPT(str, encryptionKey))`

  4. decryptData - `SELECT CAST(AES_DECRYPT(UNHEX(encrypted), encryptionKey) as CHAR)`

Usage

const { castQuery , customQuery , encryptData, decryptData } = require('sequelize-encryption');
  1. castQuery(tableField, encryptionKey);

    | column | type | |-----------------|---------------| | tableField | String | | encryptionKey | String |

  2. customQuery( names = [],castName = "",encryption = "",aliasName = "",tableName = "");

    | column | type | |-----------------|---------------| | names | Array | | castName | String | | encryption | Array | | aliasName | String | | tableName | String |

  3. encryptData(tableField,encryptionKey);

    | column | type | |-----------------|---------------| | data | String | | encryptionKey | String |

  4. decryptData(encryptedValue,encryptionKey);

    | column | type | |----------------- |---------------| | encryptedValue | String | | encryptionKey | String |

Examples

Currently there are 4 methods added.

  1. castQuery

    It is more useful when you findAll a model and you need to get a encrypted field changed into decrypted field.


    Ex : let persons = await this.personModel.findAll(query);

    let query= {
      attributes:{
        include: [
            [
              sequelize.literal(
                `CAST(AES_DECRYPT(UNHEX(firstName),${encryptionKey}) AS CHAR(50))`
              ),
              'decryptedFirstName',
            ],
          ]
      }}
  Instred of using `CAST(AES_DECRYPT(UNHEX(firstName),${encryption}) AS CHAR(50))`
  now we can use,

   let query= {
      attributes:{
        include: [
              [
                sequelize.literal(
                 castQuery(firstName,encryptionKey)
                ),
                'decryptedFirstName',
              ],
              ]
       }}
castQuery(firstName,encryptionKey);
NOTE :When passing the encryptionKey wrap with ''
  1. Custom Query

Actual Query :

SELECT id,field2,field3,CAST(AES_DECRYPT(field2, '098a4ad28mde3c4435009c9613749222') AS CHAR(50)) decrypedField FROM     personTable`;

With Sequelize-encryption actual query :

SELECT ${names.join(",")},CAST(AES_DECRYPT(${castName}, '${encryption}') AS CHAR(50)) ${aliasName} FROM ${tableName}`;

With Sequelize-encryption function :

customQuery(['field1','field2],'field1','3c7a4eb821c141726cebd608862da861','decryptedField','personTable');
  1. Encrypt Query & Decrypt Query

You can decrypt and encrypt as same as mysql native functions AES_ENCRYPT and AES_DECRYPT. In this module,we are using the same method used to encrypt and decrypt as mysql.

const { encryptData } = require('sequelize-encryption'); 

let encryptedFirstName=encryptData(data,encryptionKey);

let decryptFirstName=encryptData(encryptedFirstName,encryptionKey);

| column | type | |-----------------|---------------| | data | String | | encryptionKey | String |

|TYPE|Code|Mysql Query| |---|---|---| | String | encryptData(str, encryptionKey) | SELECT HEX(AES_ENCRYPT(str, encryptionKey)) | | String | decryptData(encryptedField, encryptionKey) | SELECT CAST(AES_DECRYPT(UNHEX(encrypted), encryptionKey) as CHAR)

Run tests

npm test

Author

👤 mithelan

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2022 mithelan.