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 🙏

© 2024 – Pkg Stats / Ryan Hefner

strong-cryptor

v2.2.0

Published

Strong encryptor and decryptor nodejs

Downloads

303

Readme

StrongCryptor

Pure javascript/typescript encryption without any depedencies

Travis (.org) Codacy Badge npm version

strong-cryptor is lightweight utility to manage strong encryption and decryption with aes-256-cbc algorithm, strong-cryptor not using any depedencies to process the encryption and decryption, with strong-cryptor you can simplify the process of encryption and decryption as simple as just calling encrypt() and decrypt function. This library is pure Javascript library built with Typescript targeting ECMAScript 5(ES5), so it's compatible with most Node.Js backend or Javascript frontend applications.

List of Contents

Background

Idea behind this project is to avoid the same pattern of every encrypted data that can be learned by attacker and make it easy to decrypted by the attacker. with strong-cryptor every encryption process will have different result, even the data is same

Changes Log (What's New)

What's New in 2.2.0

  • File encryption support.
  • Add new feature to write the result of encryption/decryption to a file.
  • Change function base to class base.

For full changelog, please refers to Release Page.

Deprecation

The old encrypt() and decrypt() function are deprecated, and will be fully removed in version 3.0.0, please use class base instead.

Basic Concept

Encryption Concept

Concept behind strong-cryptor is to create randomize IV(Initial Vector) in every encryption process, and embed the IV to the result of encryption process

| Command | Result | | --------------- | ---------------------- | | encrypt('test') | a0aade621f5e00dd21.... | | encrypt('test') | d0dac814ee1f11be08.... |

Encryption Count Concept

Concept behind Encryption Count feature is to enable strong-cryptor to encrypt more than 1 times. example if you want tou encrypt text Hello guys, i am just plain text for 3 times

| Encryption Count | Result | | ---------------- | -------------------------------------------------------------------- | | 0 | Hello guys, i am just plain text | | 1 | EiTvqlAtcXPhT5k+LZDhGQH1eAtUrczPsY... | | 2 | zH2bXMRM3iYl6ZCRB2J3bgx8kXo9LaXy+iBJeJwOmTS7OWfGXBk/nIDR... | | 3 | U2ghFawbO2VGhsk/l+bc/QYUzBLAXQJsrhkyzRK8s0GTGIuO+OUQMt3s57J2nPUD.... |

with this concept, the encryption result will more hard for the attacker to learn the pattern of the encryption process.

Note : size of encryption result depends on how many times the encryption run

Installation

To get this library included on your project, first, you can use package manager like npm or yarn command to get strong-cryptor.

npm i strong-cryptor

or

yarn add strong-cryptor

Documentation

For full documentation please refers to Doc folder.

Basic Encryption

To use strong-cryptor encryption first import Encryptor class from strong-cryptor

import { Encryptor } from 'strong-cryptor'

then create a key and new instance of Encryptor class with following parameters

import { Encryptor } from 'strong-cryptor'
const key = 'AHBSGTEUET125STSGBDHDJKXMPLKIU12' // store this key in secure place
const encryptor = new Encryptor({ key })

then encrypt your data with encrypt(data)

import { Encryptor } from 'strong-cryptor'
const data = 'your sensitive data'
const key = 'AHBSGTEUET125STSGBDHDJKXMPLKIU12' // store this key in secure place
const encryptor = new Encryptor({ key })
const encryptedData = encryptor.encrypt(data)

The code above will use aes-256-cbc encryption algorithm and base64 encoding as default encoding.

And to use strong-cryptor decryption you need import Decryptor class from strong-cryptor

import { Decryptor } from 'strong-cryptor'

Then create new instance of Encryptor class with following parameters

Full code :

import { Encryptor } from 'strong-cryptor'
const data = 'your sensitive data'
const key = 'AHBSGTEUET125STSGBDHDJKXMPLKIU12' // store this key in secure place
const encryptor = new Encryptor({ key })
const encryptedData = encryptor.encrypt(data)
const decryptor = new Decryptor({ key })
decryptor.decrypt(encryptedData)

Using Encryption Count

To make sure your encrypted data is secure, strong-cryptor providing a new feature called Encryption Count, this feature will encrypt your data as many as you want.

To use this feature you only need to fill up the encryption options.

import { Encryptor } from 'strong-cryptor'
const data = 'your sensitive data'
const key = 'AHBSGTEUET125STSGBDHDJKXMPLKIU12' // store this key in secure place
const encryptor = new Encryptor({ key, encryptionCount: 5 })
const encryptedData = encryptor.encrypt(data)
const decryptor = new Decryptor({ key, encryptionCount: 5 })
decryptor.decrypt(encryptedData)

Or

import { Encryptor } from 'strong-cryptor'
const data = 'your sensitive data'
const key = 'AHBSGTEUET125STSGBDHDJKXMPLKIU12' // store this key in secure place
const encryptor = new Encryptor({ key })
const encryptedData = encryptor.encrypt(data, { encryptionCount: 5 })
const decryptor = new Decryptor({ key })
decryptor.decrypt(encryptedData, { encryptionCount: 5 })

Make sure that you provide the encryptionCount at the decryption process too.

File Encryption

From version 2.2.0 strong-cryptor support for encrypting a file.

import { Encryptor } from 'strong-cryptor'
const key = 'AHBSGTEUET125STSGBDHDJKXMPLKIU12' // store this key in secure place
const encryptor = new Encryptor({ key })
const encryptedData = encryptor.encryptFile('path_to_your_file')
const decryptor = new Decryptor({ key })
decryptor.decryptFile(encryptedData, { toBuffer: true })

Write to File

If you want to write your encryption/decryption result to some file, just fill up writeToFile property in encryption/decryption options.

import { Encryptor } from 'strong-cryptor'
const data = 'your sensitive data'
const key = 'AHBSGTEUET125STSGBDHDJKXMPLKIU12' // store this key in secure place
const encryptor = new Encryptor({ key })
const encryptedData = encryptor.encrypt(data, { writeToFile: 'path_to_file' })
const decryptor = new Decryptor({ key })
decryptor.decrypt(encryptedData, { writeToFile: 'path_to_file' })

Generate Key

strong-cryptor can also generate a key for encryption/decryption process.

but we don't guarantee that the key is secure.

import { genKey } from 'strong-cryptor'
const key = genKey() // please store this key in the safe place

The genKey() will return a 256bits / 32 characters string.

Built With

Written in TypeScript, built into ECMAScript 5 using the TypeScript compiler.

Contribution

This project already using Travis for CI/CD purpose, and Codacy for code review and analytics. To contribute, simply fork this project, and issue a pull request.

This project using commitizen & cz-conventional-changelog for commit purpose, make sure when you commit a new change, you're using yarn commit instead of git commit or your PR will be rejected.

Version Management

We use SemVer for version management and semantic-release for automated release. For the versions available, see the releases on this repository.

Authors

See also the list of contributors who participated in this project. .