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

asymmetric-encryption

v1.2.3

Published

Asymmetric encryption on the server

Downloads

34

Readme

  1. Generate public key and private key in the server.
  2. Forward the public key to your apps (website or app)
  3. Have your app generate a random key for encryption.
  4. Encrypt the message using the random key generated by your app.
  5. Encrypt the random key using the public key supplied by the server.
  6. Send to the server both the encrypted message and the encrypted random string.
  7. On the server end decrypt the encrypted string sent by the client using private key.
  8. Using the decrypted key decrypt the message.

This module aims at solving the public key, private key and passphase part of the process.

Installation

npm i --save asymmetric-encryption

or

yarn add asymmetric-encryption

Usage

const encrypt = require("asymmetric-encryption")

const { publicKey, privateKey, passphrase } = encrypt.generateKeyPairSync();
const message = "message";

const enc = encrypt.encrypt(publicKey, message);
const dec = encrypt.decrypt(privateKey, enc);

console.log(publicKey)
console.log(privateKey)
console.log(passphrase)
console.log(dec)

Output should be

-----BEGIN PUBLIC KEY-----
MIICIjANBgkqh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