node-forge
Pure JavaScript cryptography toolkit providing hashing, RSA keys, X.509 certificates, and TLS primitives in Node and browsers.
Official Documentation ↗v1. Check the official docs for the latest API surface.Installation
npm install node-forgepnpm add node-forgeMethods
No methods match this filter.
Overview
node-forge is a pure JavaScript cryptography toolkit covering hashing, RSA keys, X.509 certificates, and TLS primitives in Node and browsers. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.
Core APIs
forge.md.sha256.create— Creates a SHA-256 digest object that you update and then finalize to read the hash.forge.pki.rsa.generateKeyPair— Generates an RSA key pair asynchronously for the requested modulus size.forge.pki.publicKeyFromPem— Parses a PEM-encoded public key into a usable object for encryption or verification.
Example
const forge = require('node-forge');
const md = forge.md.sha256.create();
md.update('hello');
console.log(md.digest().toHex());
Notes
Because it is JavaScript-only it is slower than native crypto; use it where portability matters and native modules are unavailable.
Verification
Hash a known string with SHA-256 and confirm the hex digest matches the published test vector.
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/digitalbazaar/forge@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:11.693Z.
- It is not recommended that you set this flag as native code is typically more performant and may have stronger security properties. (https://cdn.jsdelivr.net/gh/digitalbazaar/forge@latest/README.md)
- Security Considerations ———————– When using this code please keep the following in mind: - Cryptography is hard. (https://cdn.jsdelivr.net/gh/digitalbazaar/forge@latest/README.md)
FAQ
- Is node-forge suitable for high-volume cryptography?
- It is pure JavaScript and slower than native bindings, so for performance-critical paths prefer the built-in crypto module or native libs.
- How do I generate a self-signed certificate?
- Create a key pair, build a certificate with forge.pki.createCertificate, set the subject and publicKey, sign it with cert.sign(privateKey), then convert to PEM.
- Which RSA paddings are supported?
- publicKey.encrypt accepts RSAES-PKCS1-V1_5 and RSA-OAEP; use RSA-OAEP for new code.
Report a problem with this API docOpens a pre-filled issue on GitHub.