Registry / security / crypto-javascript

crypto-javascript

JSON →
library4.3.6jsnpmunverified

JavaScript library of cryptographic standards. Provides implementations of hash functions (MD5, SHA-1, SHA-256, SHA3, RIPEMD-160), HMAC, symmetric ciphers (AES, DES, TripleDES, RC4, Rabbit, RabbitLegacy, PBKDF2, EvpKDF) and encoders (Base64, Hex, Latin1, Utf8, Utf16). Ideal for client-side encryption where Node.js crypto module is unavailable. Version 4.3.6 is the latest stable release. It is a direct port of popular C++ crypto++ library algorithms to JavaScript, with no external dependencies. Not recommended for new projects due to security concerns (insecure default modes, lack of authenticated encryption). Use the Web Crypto API or Node.js crypto module instead.

npm install crypto-javascript
INSTALL
IMPORT
SIG · CRYPTO-JAVASCRIPT
C
crypto-javascript
securityjavascriptv4.3.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AES
import AES from 'crypto-js/aes'
import { AES } from 'crypto-js'
Default import from module; named import not available.
SHA256
import SHA256 from 'crypto-js/sha256'
const SHA256 = require('crypto-js').SHA256
ESM default import works; require works but is CommonJS.
enc.Hex
import encHex from 'crypto-js/enc-hex'
import { enc } from 'crypto-js'; enc.Hex
crypto-js uses deep imports for tree shaking; full library import works but not tree-shakeable.

Encrypt and decrypt a string using AES with a passphrase. Shows import of specific modules and conversion to/from strings.

import AES from 'crypto-js/aes'; import encUtf8 from 'crypto-js/enc-utf8'; import encBase64 from 'crypto-js/enc-base64'; const key = 'Secret Passphrase'; const plaintext = 'Hello World'; // Encrypt const ciphertext = AES.encrypt(plaintext, key).toString(); console.log('Ciphertext:', ciphertext); // Decrypt const bytes = AES.decrypt(ciphertext, key); const decrypted = bytes.toString(encUtf8); console.log('Decrypted:', decrypted);
Debug
Known issues
deprecatedcrypto-js uses insecure defaults: ECB mode and no padding. This is vulnerable to pattern analysis.
fix
Use Web Crypto API (SubtleCrypto) or Node.js crypto module with authenticated encryption like AES-GCM.
affects: >=0.0.0
gotchaWhen encrypting with a passphrase, crypto-js uses a default 256-bit key, but the salt is random and not stored. Decryption fails if passphrase is wrong but no error thrown.
fix
Always handle decryption result: if returned string is empty, decryption failed.
affects: >=0.0.0
breakingIn version 4.0.0, the package was rewritten as ECMAScript modules. Import paths changed.
fix
Use deep imports like 'crypto-js/aes' instead of 'crypto-js'.
affects: >=4.0.0
Errors
Common errors & fixes
Error: Cannot find module 'crypto-js/core'
Importing internal modules not exposed in package.json exports.
fix
Only import modules listed in package.json, e.g., 'crypto-js/aes' or 'crypto-js/sha256'.
TypeError: AES.decrypt(...).toString is not a function
Decrypt result is a WordArray object; .toString() works but requires an encoder.
fix
Use .toString(encUtf8) or .toString(encHex).
Upgrade
Version history
4.3.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
crypto-javascript — npm install crypto-javascript · libregistry