New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@ravshansbox/browser-crypto

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ravshansbox/browser-crypto

Node.js crypto module subset for browser


Version published
Maintainers
1
Created

Node.js 'crypto' module subset for browser

Package contents:

  • Buffer
  • getCiphers()
  • createECDH()
  • createCipher() (deprecated, use createCipheriv() instead)
  • createCipheriv()
  • createDecipher() (deprecated, use createDecipheriv() instead)
  • createDecipheriv()

Usage example:

import { Buffer, createECDH, createCipheriv, createDecipheriv } from 'browser-crypto';

const ecdh1 = createECDH('secp256k1');
const ecdh2 = createECDH('secp256k1');

const publicKey1 = ecdh1.generateKeys();
const publicKey2 = ecdh2.generateKeys();

const secret1 = ecdh1.computeSecret(publicKey2);
const secret2 = ecdh2.computeSecret(publicKey1);

const iv = Buffer.alloc(16);
const data = Buffer.from('abcdef');

const cipher = createCipheriv('aes256', secret1, iv);
const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);

const decipher = createDecipheriv('aes256', secret2, iv);
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
console.log(decrypted.toString());

FAQs

Package last updated on 15 Mar 2021

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