Encrypt sensitive form fields like passwords client-side before they are sent over the network
Verify digital signatures on messages to confirm they came from the expected sender and were not altered
Generate RSA key pairs in JavaScript for testing or prototype encryption flows without leaving the browser
Protect credit card numbers or other sensitive user input by encrypting them before transmission
No dependencies needed, just import the library and load your PEM key, use OpenSSL to generate production-quality key pairs.
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.
← travist on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.