{"id":26340,"library":"rsa-compat","title":"rsa-compat","description":"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.","status":"active","version":"2.0.8","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","RSA","ursa","forge","certificate","csr","tls","ssl","windows"],"install":[{"cmd":"npm install rsa-compat","lang":"bash","label":"npm"},{"cmd":"yarn add rsa-compat","lang":"bash","label":"yarn"},{"cmd":"pnpm add rsa-compat","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import; also supports CJS require, but ESM is preferred for newer Node versions.","wrong":"const RSA = require('rsa-compat').RSA","symbol":"RSA","correct":"import { RSA } from 'rsa-compat'"},{"note":"Default export is available only in ESM; CJS require gets the module object.","wrong":"const rsaCompat = require('rsa-compat')","symbol":"rsa-compat (default)","correct":"import rsaCompat from 'rsa-compat'"},{"note":"Named export from module; accessible via destructuring.","wrong":"const { generateKeypair } = require('rsa-compat').RSA","symbol":"generateKeypair","correct":"import { generateKeypair } from 'rsa-compat'"}],"quickstart":{"code":"import { RSA } from 'rsa-compat';\n\nconst options = { bitlen: 2048, exp: 65537, public: true, pem: true };\nRSA.generateKeypair(options, (err, keypair) => {\n  if (err) throw err;\n  console.log('Private Key PEM:', keypair.privateKeyPem);\n  console.log('Public Key PEM:', keypair.publicKeyPem);\n  console.log('Private Key JWK:', keypair.privateKeyJwk);\n  console.log('Public Key JWK:', keypair.publicKeyJwk);\n});","lang":"javascript","description":"Generates an RSA keypair with PEM and JWK exports using async callback."},"warnings":[{"fix":"Pass options object: RSA.generateKeypair({ bitlen: 2048, exp: 65537, ... }, cb).","message":"RSA.generateKeypair(bitlen, exp, options, cb) is deprecated; use RSA.generateKeypair(options, cb) with options object.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use RSA.import({ keypair: keypair, ...options }).","message":"RSA.import(keypair, options) signature changed; now RSA.import(options).","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Provide header and protect arguments: RSA.signJws(keypair, header, protect, payload).","message":"RSA.signJws(keypair, payload, nonce) replaced with RSA.signJws(keypair, header, protect, payload).","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"If you need ursa, install it explicitly: npm install ursa-optional.","message":"ursa-optional is an optional dependency but may be required on older Node versions; without it, node-forge is used.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `import { RSA } from 'rsa-compat'` instead of `import RSA from 'rsa-compat'`.","cause":"Incorrect import: using default import instead of named import.","error":"Error: RSA.generateKeypair is not a function"},{"fix":"Install ursa-optional: `npm install ursa-optional` or set NODE_OPTIONS to skip.","cause":"Optional dependency not installed or not found.","error":"Cannot find module 'ursa-optional'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}