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

sjcl

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sjcl

Stanford Javascript Crypto Library

  • 1.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
146K
increased by11.1%
Maintainers
2
Weekly downloads
 
Created

What is sjcl?

The Stanford Javascript Crypto Library (SJCL) is a library for cryptography in JavaScript. It provides a variety of cryptographic functions including encryption, hashing, and key derivation.

What are sjcl's main functionalities?

Encryption and Decryption

This feature allows you to encrypt and decrypt messages using a password. The `sjcl.encrypt` function takes a password and plaintext message, returning an encrypted string. The `sjcl.decrypt` function takes the same password and the encrypted string to return the original plaintext.

const sjcl = require('sjcl');

// Encrypt a message
const password = 'password123';
const plaintext = 'Hello, World!';
const encrypted = sjcl.encrypt(password, plaintext);
console.log('Encrypted:', encrypted);

// Decrypt the message
const decrypted = sjcl.decrypt(password, encrypted);
console.log('Decrypted:', decrypted);

Hashing

This feature allows you to hash messages using the SHA-256 algorithm. The `sjcl.hash.sha256.hash` function takes a message and returns a hash in bit array format. The `sjcl.codec.hex.fromBits` function converts the bit array to a hexadecimal string.

const sjcl = require('sjcl');

// Hash a message
const message = 'Hello, World!';
const hash = sjcl.hash.sha256.hash(message);
const hashHex = sjcl.codec.hex.fromBits(hash);
console.log('Hash:', hashHex);

Key Derivation

This feature allows you to derive cryptographic keys from passwords using the PBKDF2 algorithm. The `sjcl.misc.pbkdf2` function takes a password, salt, iteration count, and key length, returning a derived key in bit array format. The `sjcl.codec.hex.fromBits` function converts the bit array to a hexadecimal string.

const sjcl = require('sjcl');

// Derive a key from a password
const password = 'password123';
const salt = sjcl.random.randomWords(2, 0); // Generate a random salt
const key = sjcl.misc.pbkdf2(password, salt, 1000, 256);
const keyHex = sjcl.codec.hex.fromBits(key);
console.log('Derived Key:', keyHex);

Other packages similar to sjcl

Keywords

FAQs

Package last updated on 10 Nov 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