Browserify Sign

4.2.5 · maintenance · verified Sun Apr 19

browserify-sign is a JavaScript library that provides browser-compatible implementations of Node.js's `crypto` module public key functions, specifically `createSign` and `createVerify`. This allows developers to use cryptographic signing and verification operations, typically involving RSA or DSA algorithms, directly in web browsers by bundling their code with Browserify. The current stable version is 4.2.5, last published approximately seven months ago (as of April 2026). The project maintains a sustainable release cadence with at least one new version released annually, primarily focusing on maintenance and security updates rather than active feature development. Its key differentiator is enabling Node.js-style crypto APIs in browser environments, making it crucial for projects requiring consistent cryptographic behavior across server and client-side JavaScript when using the Browserify bundling approach.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use `browserify-sign` to sign data with a private key and verify it with a public key, mirroring Node.js crypto API. Key generation is shown using Node's native crypto, but in a browser, keys would be pre-loaded.

const { Sign, Verify } = require('browserify-sign');
const crypto = require('crypto'); // Node.js 'crypto' for key generation (use pre-generated keys in browser)

// In a browser environment, you would typically load pre-existing private and public keys.
// For demonstration purposes, we generate them (requires Node.js crypto module).
// NEVER hardcode keys in production.
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
  modulusLength: 2048,
  publicKeyEncoding: { type: 'spki', format: 'pem' },
  privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
});

const data = 'This is the message to be signed.';
const algorithm = 'sha256'; // Hashing algorithm, e.g., 'sha256', 'rsa-sha256'

// --- Signing Process ---
const signer = new Sign(algorithm);
signer.update(data);
signer.end(); // Indicate no more data will be written

// The privateKey must be loaded securely.
const signature = signer.sign(privateKey, 'base64');
console.log('Generated Signature:', signature);

// --- Verification Process ---
const verifier = new Verify(algorithm);
verifier.update(data);
verifier.end(); // Indicate no more data will be written

// The publicKey must be loaded securely.
const isVerified = verifier.verify(publicKey, signature, 'base64');
console.log('Signature Verification Result:', isVerified);

if (isVerified) {
  console.log('The signature is valid for the data and public key.');
} else {
  console.error('The signature is NOT valid.');
}

view raw JSON →