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

rsa-bridge

v1.1.6

Published

Encrypted communication bridge between client and server using Node-RSA library

Downloads

3

Readme

RSA-BRIDGE

Encrypted communication bridge between client and server using Node-RSA library.
  • Encrypted Communication
  • Streamlined Client-Server Integration
  • Development simplification
  • Key Generation
  • Powered by a solid library

The library uses Node-RSA to create a bridge between server-client with encrypted communication, enabling secure end-to-end communication.

RSA Client Image

Example

RSA Bridge Server Instance

import { RSAServer } from "rsa-bridge";
const rsa = new RSAServer({ bits: 1024 });

app.use(
  rsa.gate((req, res, next) => {
    // your handler functions
  })
);

RSA Bridge Client Instance

import { RSAClient } from "rsa-bridge";
const rsa = new RSAClient({ bits: 1024 });

rsa.connect(PATH);
rsa.fetch(INPUT, OPTIONS);

Installing

npm install rsa-bridge

Testing

npm test

Usage

Its use is divided into an client instance (RSAClient) and an server instance (RSAServer). The server instance must expose the public key (publish) and have the middleware (gate) to inject RSA into the handler. The client instance must have the public key exposure endpoint (connect) to encrypt the data.

Instantiating

To instantiate the service on the server it is necessary to specify bits or keys that will be used. Below is an example of instantiating the model used both on the server and on the client

import { BasicRSA } from "rsa-bridge";
const rsa = new BasicRSA(BasicRSAConfig);
  • random - BasicRSAConfig - you can generate random keys by entering the bits
{
  bits: number;
}
  • custom - BasicRSAConfig - you can specify your keys using the configuration below
{
  keys: {
    private: string,
    public: string,
    ...
  }
}

Client-side

Instantiating

The instance configuration is the same as found here. Although it is possible, a custom key is not recommended for clients.

import { RSAClient } from "rsa-bridge";
const rsa = new RSAClient(BasicRSAConfig);

Connect

Obtains a connection to the server's RSA service, via the endpoint defined for public key exposure. The PATH must point to the address defined here.

rsa.connect(PATH);

Fetch

Execute a request to the server using the encryption bridge.

rsa.fetch(INPUT, OPTIONS).then(({ body, response }) => {
  // decrypted data
});

Server-side

Instantiating

The instance configuration is the same as found here.

import { RSAServer } from "rsa-bridge";
const rsa = new RSAServer(BasicRSAConfig);

Publish

The public key must be exposed for the bridge to work. The method must be GET.

app.get(PATH, rsa.publish);
  • path - string - the HTTP path

Gate

It can be used as a middleware, propagating the service to all routes

app.use(rsa.gate);
app.post("example", HANDLER);

It can also be used on a , as in the single path

app.post("/example", rsa.gate(HANDLER));

Getting Data

If the request passed the gate, the data sent in the body can be obtained

app.use(rsa.gate);
app.post("/example", (req, res) => {
  req.body; // decrypted data
});

Send

The send function will be wrapped by the gate to encrypt the data before sending it to the client. Predecessors like .json() and .status() can be used as well.

app.use(rsa.gate);
app.post("/example", (req, res) => {
  res.status(200).send(DATA); // L0SQ23.....
});

The wrapped res will extend throughout the request until the response, even with the use of next() for example.

app.use(rsa.gate);
app.use((req, res, next) => {
  next();
});
app.use((req, res) => {
  res.status(200).json(DATA); // L0SQ23.....
});

Basic RSA Functions

Encrypt

Returns encrypted data as base64

const encrypted = rsa.encrypt(data);

Decrypt

returns decrypted data as utf8

const decrypted = rsa.decrypt(data);

encryptWithKey

returns encrypted data as base64 encrypted with a different key

const encrypted = rsa.encryptWithKey(key, data, format?);

publicKey

exports the node's public key. The default encoding is "UTF8" but can be changed.

const publicKey = rsa.publicKey(KeyFormat, OutputEncoding);

ReactJS Example

An example implementation with reactJS is available in examples. There is a live version at https://rsa-bridge.vercel.app

CI npms.io GitHub commit activity