Get started with sjcl CDN

(GPL-2.0 OR BSD-2-Clause) licensed

SJCL is a lightweight cryptography library written in JS.

Tags:
  • encryption
  • high-level
  • crypto

Stable version

Copied!

How to start using sjcl CDN


// Include SJCL library from CDN
const sjclScript = document.createElement('script');
sjclScript.src = 'https://cdn.cdnhub.io/sjcl/1.0.8/sjcl.min.js';
document.head.appendChild(sjclScript);

// Wait for SJCL library to load
window.addEventListener('load', () => {
  // Initialize SJCL with AES key length 256 bits
  const SJCL = sjcl;
  SJCL.quickLoad();
  const key = new SJCL.crypto.PRNG().randomWords(1, 32);

  // Encrypt a message using AES encryption
  const message = 'Hello, world!';
  const encrypted = SJCL.encrypt(message, key, { mode: 'CBC', iv: SJCL.random() });

  // Decrypt the encrypted message using the same key
  const decrypted = SJCL.decrypt(encrypted, key);

  console.log('Original message:', message);
  console.log('Encrypted message:', encrypted.encrypted.toString(SJCL.util.hex));
  console.log('Decrypted message:', decrypted.plaintext.toString(SJCL.util.utf8));
});
Copied!
Copied!
Copied!

All versions