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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dae54/enc

v1.2.4

Published

This is a wrapper to `"crypto-js": "^3.3.0"` assisting in easy encryption and decryption using AES-256

Downloads

90

Readme

General

This is a wrapper to "crypto-js": "^3.3.0" assisting in easy encryption and decryption using AES-256

Installation

npm i @dae54/enc

This will install @dae54/enc

Usage

This package exposes 2 public methods, encrypt and decrypt serving purposes as stating.

  • Start by instantiating the class Enc by providing encryption key
const EncHandler = require('@dae54/enc')
const hashKey = 'some random generated key'
const encHandler = new EncHandler(hashKey)

// Here encHandler will have exposed  2 methods
encHandler.encrypt(payload,fields)
encHandler.decrypt(payload,fields)

Objects

Sample payload

const payload = {
    id: '1',
    price: '80000',
    sales: '900000',
    units: '100'
}

Encryption

Use encrypt(payload,fieldsToEncrypt) instance of encHandler

const fieldsToEncrypt = ['price', 'sales']
const encrypted = encHandler.encrypt(payload,fields)

Output (encrypted)

{
    id: '1',
    price: 'U2FsdGVkX18RYNPLtly/ykEjLOQpgtc3ekGyesTCbOo=',
    sales: 'U2FsdGVkX18KW6tBWBmbsojBiqyKsqWhVVvcBO39c80=',
    units: '100',
}  

Decryption

Use decrypt(payload,fieldsToDecrypt) instance of encHandler

const payload = {
    id: '1',
    price: 'U2FsdGVkX18RYNPLtly/ykEjLOQpgtc3ekGyesTCbOo=',
    sales: 'U2FsdGVkX18KW6tBWBmbsojBiqyKsqWhVVvcBO39c80=',
    units: '100',
}
const fields = ['price', 'sales']
const decrypted = encHandler.decrypt(payload,fields)

Output (decrypted)

{
    id: '1',
    price: '80000',
    sales: '900000',
    units: '100',
}

Nested Objects (1-Level)

Sample payload

const payload = {
    id: '1',
    price: '80000',
    sales: '900000',
    units: '100',
    buyer:{
        name:"test name",
        id:"uu"
    }   
}

Encryption

Use encrypt(payload,fieldsToEncrypt) instance of encHandler, adding the nested objects keys using dot operator. See (buyer.name) below

const fields = ['price', 'sales', 'units','buyer.name']
const encrypted = encHandler.encrypt(payload,fields)

Output (encrypted)

{
    id: '1',
    price: 'U2FsdGVkX18RYNPLtly/ykEjLOQpgtc3ekGyesTCbOo=',
    sales: 'U2FsdGVkX18KW6tBWBmbsojBiqyKsqWhVVvcBO39c80=',
    units: 'U2FsdGVkX19yy5FQJvn3iUOxE7aLi5zmN6Kl06Tvbno=',
    buyer:{
         name:"U2FsdGVkX19yy5FQJvn3iUOxE7ybiidoo933dodC=",
         id:"uu"
    }
}  

Decryption

To Decrypt,an object item, call decrypt(payload,fields) instance of encHandler, taking note of dot operator for nested objects encrypted.

Sample Payload

const payload = {
    id: '1',
    price: 'U2FsdGVkX18RYNPLtly/ykEjLOQpgtc3ekGyesTCbOo=',
    sales: 'U2FsdGVkX18KW6tBWBmbsojBiqyKsqWhVVvcBO39c80=',
    units: 'U2FsdGVkX19yy5FQJvn3iUOxE7aLi5zmN6Kl06Tvbno=',
    buyer:{
        name:"U2FsdGVkX19yy5FQJvn3iUOxE7ybiidoo933dodC=",
        id:"uu"
    }   
}
const fields = ['price', 'sales', 'units','buyer.name']
const decrypted = encHandler.decrypt(payload,fields)

Output (decrypted)

{
    id: '1',
    price: '80000',
    sales: '900000',
    units: '100',
    buyer:{
        name:"test name",
        id:"uu"
    } 
}

Nested Objects Level - 2 and more

Not supported

Arrays

Sample Payload

const payload = {
    id: '1',
    price: '90000',
    products: [
        {
            id: '1',
            price: '80000',
            sales: '800000',
        },
        {
            id: '2',
            price: '180000.998',
            sales: '800005.2',
        },
    ]
}

Encryption

Use encrypt(payload,fieldsToEncrypt,arrayFieldsToEncrypt) instance of encHandler.

const fields = ['price']
const arrayFieldsToEncrypt = ['products:[id,price]']
const encrypted = encHandler.encrypt(payload,fields,arrayFieldsToEncrypt)

Output (Encrypted)

const payload = {
    id:'1'
    price: 'U2FsdGVkX1+tmXBzY8KnpdEbZhD6U7s+MVLqdOyEl+U=',
    products: [
        {
            id: 'U2FsdGVkX1+RCt+erbceDwRVmfz18eKns74swXjH+ww=',
            price: 'U2FsdGVkX1864K0TmWXa3lOe49AQW61jd2d7nMLx3q8=',
            sales: '800000'
        },
        {
            id: 'U2FsdGVkX19lgyE/UG2QHollWHKM1VT2NCCLnTBD454=',
            price: 'U2FsdGVkX19AXOsKSW+ulmM/sBG9JgvvPufwdwhVqn4=',
            sales: '800005.2'
        }
    ]
}

Decryption

To Decrypt,an object item, call decrypt(payload,fields,fieldsToDecrypt) instance of encHandler. Sample Payload

{
    id:'1'
    price: 'U2FsdGVkX1+tmXBzY8KnpdEbZhD6U7s+MVLqdOyEl+U=',
    products: [
        {
            id: 'U2FsdGVkX1+RCt+erbceDwRVmfz18eKns74swXjH+ww=',
            price: 'U2FsdGVkX1864K0TmWXa3lOe49AQW61jd2d7nMLx3q8=',
            sales: '800000'
        },
        {
            id: 'U2FsdGVkX19lgyE/UG2QHollWHKM1VT2NCCLnTBD454=',
            price: 'U2FsdGVkX19AXOsKSW+ulmM/sBG9JgvvPufwdwhVqn4=',
            sales: '800005.2'
        }
    ]
}


const fields = ['price']
const arrayFieldsToDecrypt = ['products:[id,price]']
const decrypted = encHandler.decrypt(payload,fields,arrayFieldsToDecrypt)

Output

const payload = {
    id: '1',
    price: '90000',
    products: [
        {
            id: '1',
            price: '80000',
            sales: '800000',
        },
        {
            id: '2',
            price: '180000.998',
            sales: '800005.2',
        },
    ]
}

Dependencies

This package depends on:

  • "crypto-js": "3.3.0"

So It should work with NodeJs, React Native and ReactJS.