Socket
Socket
Sign inDemoInstall

@types/node-forge

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/node-forge

TypeScript definitions for node-forge


Version published
Weekly downloads
8.3M
increased by2.2%
Maintainers
1
Weekly downloads
 
Created

What is @types/node-forge?

@types/node-forge provides TypeScript type definitions for the node-forge library, which is a native implementation of TLS (and various other cryptographic tools) in JavaScript. It allows developers to perform a variety of cryptographic operations such as encryption, decryption, hashing, and digital signatures.

What are @types/node-forge's main functionalities?

Encryption and Decryption

This feature allows you to encrypt and decrypt data using the AES-CBC algorithm. The code sample demonstrates how to encrypt a simple 'Hello World' string and then decrypt it back to its original form.

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('Hello World'));
cipher.finish();
const encrypted = cipher.output;
const decipher = forge.cipher.createDecipher('AES-CBC', key);
decipher.start({iv: iv});
decipher.update(encrypted);
decipher.finish();
const decrypted = decipher.output.toString();
console.log(decrypted);

Hashing

This feature allows you to create cryptographic hashes using various algorithms like SHA-256. The code sample demonstrates how to hash a 'Hello World' string using SHA-256.

const forge = require('node-forge');
const md = forge.md.sha256.create();
md.update('Hello World', 'utf8');
const hash = md.digest().toHex();
console.log(hash);

Digital Signatures

This feature allows you to create and verify digital signatures. The code sample demonstrates how to sign a 'Hello World' string with a private key and then verify the signature with the corresponding public key.

const forge = require('node-forge');
const pki = forge.pki;
const keys = pki.rsa.generateKeyPair(2048);
const md = forge.md.sha256.create();
md.update('Hello World', 'utf8');
const signature = keys.privateKey.sign(md);
const verified = keys.publicKey.verify(md.digest().bytes(), signature);
console.log(verified);

TLS/SSL

This feature allows you to create and manage TLS/SSL certificates. The code sample demonstrates how to generate a self-signed certificate.

const forge = require('node-forge');
const pki = forge.pki;
const keys = pki.rsa.generateKeyPair(2048);
const cert = pki.createCertificate();
cert.publicKey = keys.publicKey;
cert.serialNumber = '01';
cert.validity.notBefore = new Date();
cert.validity.notAfter = new Date();
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
const attrs = [{name: 'commonName', value: 'example.org'}];
cert.setSubject(attrs);
cert.setIssuer(attrs);
cert.sign(keys.privateKey);
const pem = pki.certificateToPem(cert);
console.log(pem);

Other packages similar to @types/node-forge

FAQs

Package last updated on 27 Jul 2023

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