Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-forge

Package Overview
Dependencies
Maintainers
3
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-forge

JavaScript implementations of network transports, cryptography, ciphers, PKI, message digests, and various utilities.

  • 1.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21M
decreased by-2.05%
Maintainers
3
Weekly downloads
 
Created

What is node-forge?

The node-forge npm package is a JavaScript library that provides a variety of cryptographic functionalities including encryption, decryption, digital signatures, message digests, and key generation. It is implemented in pure JavaScript and can be used in various environments like browsers and Node.js.

What are node-forge's main functionalities?

MD5 and SHA hashing

This code sample demonstrates how to create an MD5 hash of a given string using node-forge.

const forge = require('node-forge');
const md = forge.md.md5.create();
md.update('The quick brown fox jumps over the lazy dog');
console.log(md.digest().toHex());

RSA Key Pair Generation

This code sample shows how to generate an RSA key pair with a specified key size using node-forge.

const forge = require('node-forge');
forge.pki.rsa.generateKeyPair({bits: 2048, workers: -1}, function(err, keypair) {
  console.log(keypair.privateKey);
  console.log(keypair.publicKey);
});

AES Encryption/Decryption

This code sample illustrates how to encrypt and decrypt data using AES with CBC mode in node-forge.

const forge = require('node-forge');
const key = forge.random.getBytesSync(16);
const iv = forge.random.getBytesSync(16);
const cipher = forge.cipher.createCipher('AES-CBC', key);
cipher.start({iv: iv});
cipher.update(forge.util.createBuffer('some clear text data'));
cipher.finish();
const encrypted = cipher.output;
// decryption
const decipher = forge.cipher.createDecipher('AES-CBC', key);
decipher.start({iv: iv});
decipher.update(encrypted);
decipher.finish();
console.log(decipher.output.toString());

Digital Signature Creation and Verification

This code sample demonstrates how to create and verify a digital signature using SHA-256 and RSA keys with node-forge.

const forge = require('node-forge');
const pki = forge.pki;
const md = forge.md.sha256.create();
const privateKey = pki.privateKeyFromPem(privateKeyPem);
const publicKey = pki.publicKeyFromPem(publicKeyPem);
md.update('sign this message', 'utf8');
const signature = privateKey.sign(md);
const verified = publicKey.verify(md.digest().bytes(), signature);
console.log(verified);

Other packages similar to node-forge

Keywords

FAQs

Package last updated on 30 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc