Stanford Javascript Crypto Library (SJCL)

1.0.9 · deprecated · verified Sun Apr 19

SJCL, or Stanford Javascript Crypto Library, is a high-level, open-source JavaScript cryptography library designed to provide secure and robust cryptographic primitives for web applications. While it was once a notable choice for client-side encryption, the library is officially deprecated by its maintainers. The current stable version is 1.0.9, but it has not seen significant feature development in many years, with recent updates primarily addressing critical vulnerabilities. Its release cadence is effectively stalled. Key differentiators at its prime included its focus on security best practices for in-browser cryptography and ease of use, but it is now advised against for new projects due to its age and the availability of more modern, actively maintained alternatives in the JavaScript crypto ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic encryption and decryption using AES in GCM mode and SHA-256 hashing. It shows how to use the 'sjcl' object for core cryptographic operations.

const sjcl = require('sjcl');

// Generate a random key
const password = 'mySecretPassword';
const key = sjcl.misc.stringToBits(password);

// Data to encrypt
const plaintext = 'Hello, secure world!';

// Encrypt the data
const encrypted = sjcl.json.encrypt(key, plaintext);

console.log('Encrypted data:', encrypted);

// Decrypt the data
try {
  const decrypted = sjcl.json.decrypt(key, encrypted);
  console.log('Decrypted data:', decrypted);
} catch (e) {
  console.error('Decryption failed:', e.message);
}

// Example of hashing
const dataToHash = 'This is a test string for hashing.';
const hashBits = sjcl.hash.sha256.hash(dataToHash);
const hashHex = sjcl.codec.hex.fromBits(hashBits);

console.log('SHA-256 hash:', hashHex);

view raw JSON →