explaingit

travist/jsencrypt

6,796JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A tiny JavaScript library (18.5KB) that lets you encrypt, decrypt, and digitally sign data using RSA public-key cryptography in both web browsers and Node.js, with no external dependencies.

Mindmap

mindmap
  root((JSEncrypt))
    What it does
      RSA encryption
      RSA decryption
      Digital signatures
      Key pair generation
    Tech Stack
      JavaScript
      No dependencies
    Use Cases
      Protect form fields
      Verify signatures
      Client-side crypto
    Audience
      Web developers
      Node.js developers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Encrypt sensitive form fields like passwords client-side before they are sent over the network

USE CASE 2

Verify digital signatures on messages to confirm they came from the expected sender and were not altered

USE CASE 3

Generate RSA key pairs in JavaScript for testing or prototype encryption flows without leaving the browser

USE CASE 4

Protect credit card numbers or other sensitive user input by encrypting them before transmission

Tech stack

JavaScript

Getting it running

Difficulty · easy Time to first run · 5min

No dependencies needed, just import the library and load your PEM key, use OpenSSL to generate production-quality key pairs.

In plain English

JSEncrypt is a small JavaScript library that lets you encrypt and decrypt data using RSA, a widely used public-key encryption standard. It works in both web browsers and in Node.js server environments, and the whole library weighs only about 18.5 kilobytes when compressed, which means it adds almost nothing to a website's load time. RSA encryption works with a pair of keys. The public key is used to lock (encrypt) data, and the private key is used to unlock (decrypt) it. You can share your public key with anyone, but the private key must be kept secret. JSEncrypt accepts keys in the PEM format, which is the standard text format produced by OpenSSL, a common command-line security tool. You generate a key pair with OpenSSL once, paste the keys into your code, and the library handles all the cryptographic math. The basic workflow is straightforward. You create a JSEncrypt instance, load a key into it, and call encrypt or decrypt with your data. For web apps that receive a public key from a server, you set the public key and encrypt a message on the client side. The server then decrypts it with the private key. This pattern is commonly used to protect sensitive form fields, like passwords or credit card numbers, before they travel over the network. Beyond simple encryption and decryption, JSEncrypt also supports digital signatures, which let you verify that a piece of data was produced by the holder of a specific private key and has not been altered. It supports several hash functions for signing (including SHA-256 and SHA-512) and also includes OAEP padding, a more modern encryption scheme that is harder to attack than the older default. The library can generate RSA key pairs directly in JavaScript, which is useful for testing and demos, though the README recommends using OpenSSL for any production application handling real sensitive data, since OpenSSL uses better sources of randomness. Key sizes of 1024, 2048, and 4096 bits are supported, with 2048 recommended as the minimum for serious use. There are no external dependencies, which means installing the library does not pull in any other packages.

Copy-paste prompts

Prompt 1
Using JSEncrypt, write code that encrypts a user password in the browser before submitting a login form, and show me how the server decrypts it with the private key.
Prompt 2
I need to verify a digital signature in the browser using JSEncrypt. Show me how to load a public key from my server and verify that a signed message is authentic.
Prompt 3
Set up JSEncrypt in a Node.js project to encrypt and decrypt messages using a 2048-bit RSA key pair generated with OpenSSL.
Prompt 4
Generate a temporary RSA key pair with JSEncrypt for a demo, encrypt a message with the public key, and decrypt it with the private key.
Open on GitHub → Explain another repo

← travist on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.