Socket
Socket
Sign inDemoInstall

isomorphic-webcrypto

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isomorphic-webcrypto

webcrypto library for Node, React Native and IE11+


Version published
Weekly downloads
117K
increased by11.44%
Maintainers
1
Weekly downloads
 
Created

What is isomorphic-webcrypto?

The isomorphic-webcrypto npm package provides a unified API for cryptographic operations that work seamlessly in both Node.js and browser environments. It leverages the Web Cryptography API to offer a consistent interface for tasks such as encryption, decryption, hashing, and key generation.

What are isomorphic-webcrypto's main functionalities?

Encryption and Decryption

This feature allows you to perform encryption and decryption using the AES-GCM algorithm. The code sample demonstrates generating a key, encrypting a message, and then decrypting it back to its original form.

const crypto = require('isomorphic-webcrypto');

async function encryptDecrypt() {
  const key = await crypto.subtle.generateKey({
    name: 'AES-GCM',
    length: 256
  }, true, ['encrypt', 'decrypt']);

  const data = new TextEncoder().encode('Hello, World!');
  const iv = crypto.getRandomValues(new Uint8Array(12));

  const encrypted = await crypto.subtle.encrypt({
    name: 'AES-GCM',
    iv: iv
  }, key, data);

  const decrypted = await crypto.subtle.decrypt({
    name: 'AES-GCM',
    iv: iv
  }, key, encrypted);

  console.log(new TextDecoder().decode(decrypted)); // 'Hello, World!'
}

encryptDecrypt();

Hashing

This feature allows you to create a hash of data using the SHA-256 algorithm. The code sample demonstrates hashing a string and converting the result to a hexadecimal string.

const crypto = require('isomorphic-webcrypto');

async function hashData() {
  const data = new TextEncoder().encode('Hello, World!');
  const hash = await crypto.subtle.digest('SHA-256', data);
  console.log(Buffer.from(hash).toString('hex'));
}

hashData();

Key Generation

This feature allows you to generate a pair of RSA keys for signing and verification. The code sample demonstrates generating an RSA key pair with specific parameters.

const crypto = require('isomorphic-webcrypto');

async function generateKeyPair() {
  const keyPair = await crypto.subtle.generateKey({
    name: 'RSA-PSS',
    modulusLength: 2048,
    publicExponent: new Uint8Array([1, 0, 1]),
    hash: 'SHA-256'
  }, true, ['sign', 'verify']);

  console.log(keyPair);
}

generateKeyPair();

Other packages similar to isomorphic-webcrypto

Keywords

FAQs

Package last updated on 19 Jul 2018

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