{"id":12037,"library":"sjcl","title":"Stanford Javascript Crypto Library (SJCL)","description":"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.","status":"deprecated","version":"1.0.9","language":"javascript","source_language":"en","source_url":"https://github.com/bitwiseshiftleft/sjcl","tags":["javascript","encryption","high-level","crypto"],"install":[{"cmd":"npm install sjcl","lang":"bash","label":"npm"},{"cmd":"yarn add sjcl","lang":"bash","label":"yarn"},{"cmd":"pnpm add sjcl","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primarily designed for CommonJS or global script inclusion. ESM imports are not officially supported or recommended for this deprecated library.","wrong":"import sjcl from 'sjcl';","symbol":"sjcl","correct":"const sjcl = require('sjcl');"},{"note":"Access specific modules as properties of the main 'sjcl' object after requiring the library.","symbol":"sjcl.cipher.aes","correct":"const sjcl = require('sjcl');\nconst aes = sjcl.cipher.aes;"},{"note":"Hashes like SHA-256 are exposed as properties. Ensure the correct module is loaded/available in your build.","symbol":"sjcl.hash.sha256","correct":"const sjcl = require('sjcl');\nconst sha256 = sjcl.hash.sha256;"}],"quickstart":{"code":"const sjcl = require('sjcl');\n\n// Generate a random key\nconst password = 'mySecretPassword';\nconst key = sjcl.misc.stringToBits(password);\n\n// Data to encrypt\nconst plaintext = 'Hello, secure world!';\n\n// Encrypt the data\nconst encrypted = sjcl.json.encrypt(key, plaintext);\n\nconsole.log('Encrypted data:', encrypted);\n\n// Decrypt the data\ntry {\n  const decrypted = sjcl.json.decrypt(key, encrypted);\n  console.log('Decrypted data:', decrypted);\n} catch (e) {\n  console.error('Decryption failed:', e.message);\n}\n\n// Example of hashing\nconst dataToHash = 'This is a test string for hashing.';\nconst hashBits = sjcl.hash.sha256.hash(dataToHash);\nconst hashHex = sjcl.codec.hex.fromBits(hashBits);\n\nconsole.log('SHA-256 hash:', hashHex);","lang":"javascript","description":"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."},"warnings":[{"fix":"Migrate to a modern, actively maintained cryptographic library (e.g., Web Crypto API, 'libsodium-wrappers', 'tweetnacl-js').","message":"SJCL is officially deprecated. Do not use it in new projects. Consider more modern, actively maintained alternatives due to security implications of unmaintained crypto libraries.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Upgrade to SJCL 1.0.9 immediately. For new projects, avoid SJCL entirely.","message":"A critical vulnerability (CVE-2026-XXXX) existed in sjcl.ecc.basicKey.publicKey() prior to version 1.0.9, allowing an attacker to recover ECDH private keys via crafted off-curve public keys and observing ECDH outputs. This affects ECDH key exchanges.","severity":"breaking","affected_versions":"<1.0.9"},{"fix":"Ensure you are using a stable release (1.0.9) and that your platform has a robust cryptographically secure random number generator.","message":"The development version prior to commit ac0b3fe0 (before 12.02.2014) had a paranoia bug in the ECC module. This might affect ECC key generation on platforms without a strong platform random number generator.","severity":"gotcha","affected_versions":"development versions before 2014-02-12"},{"fix":"If decoding data encoded with `base32` prior to 1.0.4, use `sjcl.codec.base32hex`. If you don't want padding on `fromBits` output, pass a truthy second parameter. Ensure your base32 encoding/decoding logic aligns with RFC 4648 or the new `base32hex`.","message":"In version 1.0.4, `sjcl.codec.base32` was re-enabled with changes to conform to RFC 4648. This changed padding behavior (now applied by default) and the encoding alphabet. The former extended hex alphabet is now `sjcl.codec.base32hex`.","severity":"breaking","affected_versions":"<1.0.4"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure your SJCL build includes the 'json' component. If using a pre-built file, verify it's the full version. If custom building, add 'json' to your components list.","cause":"Attempting to use sjcl.json for encryption/decryption without ensuring the 'sjcl.json' component is included in the build or loaded correctly.","error":"TypeError: sjcl.json is not a function"},{"fix":"Verify that the encryption key and decryption key are absolutely identical. Check for any inconsistencies in key derivation or storage. Ensure the ciphertext was not altered.","cause":"The key used for decryption does not match the key (or password from which it was derived) used during encryption, or there was corruption of the ciphertext.","error":"Error: Key doesn't match the one used to encrypt"},{"fix":"Confirm that the 'aes' component is part of your SJCL build configuration. If using a custom build, ensure 'aes' is selected. If importing, verify the module structure allows access.","cause":"The 'sjcl.cipher.aes' module was not loaded or included in the SJCL build, making `sjcl.cipher` undefined, or `aes` property inaccessible.","error":"TypeError: Cannot read properties of undefined (reading 'aes')"}],"ecosystem":"npm"}