Registry / auth-security / rsa-compat

rsa-compat

JSON →
library2.0.8jsnpmunverified

RSA utility library for Node.js that works on Windows, Mac, and Linux with or without a C compiler. Current version is 2.0.8, released under a permissive license. It wraps ursa (when available) or node-forge for key generation, import, export, signing, and CSR creation. Key differentiators include cross-platform support without native compilation, JWK export/import, and integration with ACME.js and Greenlock.js for Let's Encrypt certificate management.

npm install rsa-compat
INSTALL
IMPORT
SIG · RSA-COMPAT
R
rsa-compat
auth-securityjavascriptv2.0.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RSA
import { RSA } from 'rsa-compat'
const RSA = require('rsa-compat').RSA
ESM import; also supports CJS require, but ESM is preferred for newer Node versions.
rsa-compat (default)
import rsaCompat from 'rsa-compat'
const rsaCompat = require('rsa-compat')
Default export is available only in ESM; CJS require gets the module object.
generateKeypair
import { generateKeypair } from 'rsa-compat'
const { generateKeypair } = require('rsa-compat').RSA
Named export from module; accessible via destructuring.

Generates an RSA keypair with PEM and JWK exports using async callback.

import { RSA } from 'rsa-compat'; const options = { bitlen: 2048, exp: 65537, public: true, pem: true }; RSA.generateKeypair(options, (err, keypair) => { if (err) throw err; console.log('Private Key PEM:', keypair.privateKeyPem); console.log('Public Key PEM:', keypair.publicKeyPem); console.log('Private Key JWK:', keypair.privateKeyJwk); console.log('Public Key JWK:', keypair.publicKeyJwk); });
Debug
Known issues
breakingRSA.generateKeypair(bitlen, exp, options, cb) is deprecated; use RSA.generateKeypair(options, cb) with options object.
fix
Pass options object: RSA.generateKeypair({ bitlen: 2048, exp: 65537, ... }, cb).
affects: >=2.0.0
deprecatedRSA.import(keypair, options) signature changed; now RSA.import(options).
fix
Use RSA.import({ keypair: keypair, ...options }).
affects: >=2.0.0
deprecatedRSA.signJws(keypair, payload, nonce) replaced with RSA.signJws(keypair, header, protect, payload).
fix
Provide header and protect arguments: RSA.signJws(keypair, header, protect, payload).
affects: >=2.0.0
gotchaursa-optional is an optional dependency but may be required on older Node versions; without it, node-forge is used.
fix
If you need ursa, install it explicitly: npm install ursa-optional.
affects: >=2.0.0
Errors
Common errors & fixes
Error: RSA.generateKeypair is not a function
Incorrect import: using default import instead of named import.
fix
Use `import { RSA } from 'rsa-compat'` instead of `import RSA from 'rsa-compat'`.
Cannot find module 'ursa-optional'
Optional dependency not installed or not found.
fix
Install ursa-optional: `npm install ursa-optional` or set NODE_OPTIONS to skip.
Upgrade
Version history
2.0.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
rsa-compat — npm install rsa-compat · libregistry