API Reference

node-forge

Pure JavaScript cryptography toolkit providing hashing, RSA keys, X.509 certificates, and TLS primitives in Node and browsers.

Official Documentation ↗
CompatibilityThis documentation covers version v1. Check the official docs for the latest API surface.

Installation

npmnpm install node-forge
pnpmpnpm add node-forge

Methods

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.

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.