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

cryptify-js

v1.0.7

Published

Cryptify JS is used to encrypt and decrypt data using custom AES & RSA algorithm.

Downloads

43

Readme

cryptify-js

A simple library to encrypt and decrypt strings using AES-256-CBC & RSA algorithm. This library is written in JavaScript and can be used in both Node.js and TypeScript projects. This is very useful when you want to encrypt some sensitive data and store it in a database or send it over the network. It's tested with Nodejs & TypeScript, also supported in the browser. Tested in angular and react projects.

Features

  • Encrypt and decrypt strings using AES-256-CBC & RSA algorithm.
  • Encrypt and decrypt objects.
  • Supported in Node.js, TypeScript, and the browser.

Encryption Approach

  • Generate a random key and iv for each encryption.
  • Encrypt the data using the generated key and iv.
  • Encrypt the generated key using the public key.
  • Return the encrypted key, iv, and data.

Decryption Approach

  • Decrypt the encrypted key using the private key.
  • Decrypt the data using the decrypted key and iv.
  • Return the decrypted data.

Requirements

  • Node.js v10.0.0 or higher
  • TypeScript v4.0.0 or higher
  • RSA Public and Private Key in base64 format

Generating RSA Public and Private Key and Convert to Base64

# Generate RSA Private Key - Mac
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048

# Generate RSA Public Key - Mac
openssl rsa -pubout -in private_key.pem -out public_key.pem

# Convert Private Key to Base64 - Mac
base64 -i private_key.pem -o private_key_base64.txt
# Linux
base64 private_key.pem > private_key_base64.txt

# Convert Public Key to Base64 - Mac
base64 -i public_key.pem -o public_key_base64.txt
# Linux
base64 public_key.pem > public_key_base64.txt

License

This project is licensed under the MIT License.

Installation

npm install cryptify-js

Usage

const Cryptify = require('cryptify-js');

const cryptify = new Cryptify({
    publicKey: 'RSA PUBLIC KEY BASE64',
    privateKey: 'RSA PRIVATE KEY BASE64'
});

const data = {
    name: 'John Doe',
    email: '[email protected]',
    phone: '1234567890'
};

const encrypted = cryptify.encrypt(data);
const decrypted = cryptify.decrypt(encrypted.key, encrypted.iv, encrypted.data);

console.log('Encrypted:', encrypted);
console.log('Decrypted:', decrypted);

Supported Methods

encrypt(data: any): { key: string, iv: string, data: string }

Encrypts the given data and returns the encrypted key, iv, and data.

decrypt(key: string, iv: string, data: string): any

Decrypts the given key, iv, and data and returns the decrypted data.