सामग्री पर जाएँ
HexaTransfer
ब्लॉग पर वापस
एन्क्रिप्शन और सुरक्षा

JavaScript एन्क्रिप्शन लाइब्रेरी: डेवलपर्स के लिए टॉप पिक

वेब ऐप के लिए सर्वोत्तम JS एन्क्रिप्शन लाइब्रेरी की तुलना करें। tweetnacl से libsodium.js तक अपने प्रोजेक्ट के लिए सही लाइब्रेरी खोजें।

2026 में file transfer के लिए सबसे अच्छी JavaScript encryption libraries हैं: libsodium.js broad coverage और WASM speed के लिए, @noble/ciphers और @noble/curves modern audits के साथ pure-JS implementations के लिए, tweetnacl छोटे bundle size और NaCl-compatible primitives के लिए, crypto-js legacy compatibility के लिए (नए code के लिए avoid करें), और native Web Crypto API उन सब के लिए जो वह support करता है। यह गाइड algorithm coverage, bundle size, audit history, browser versus Node compatibility, और file encryption workloads पर real-world performance की तुलना करती है। सही pick इस पर depend करती है: आप browsers को ship कर रहे हैं, Node पर build कर रहे हैं, ChaCha20-Poly1305 या Argon2 चाहिए, या Web Crypto की bounds के भीतर रह सकते हैं।

तुलना तालिका

| Library | Size (gzipped) | Backend | Key algorithms | Audited | Modern? | |---|---|---|---|---|---| | Web Crypto API | 0 KB (native) | Browser native | AES-GCM, PBKDF2, RSA, ECDH, HMAC | हाँ (browser vendors द्वारा) | हाँ, लेकिन ChaCha/Argon2 नहीं | | libsodium.js | 200 KB WASM / 400 KB JS | WASM + JS fallback | libsodium में सब कुछ | हाँ (multiple) | हाँ | | @noble/ciphers | 8 KB | Pure JS | AES, ChaCha20, Poly1305, GCM-SIV | हाँ (Cure53 2023) | हाँ | | @noble/curves | 35 KB | Pure JS | Ed25519, X25519, secp256k1, BLS | हाँ (Trail of Bits, Cure53) | हाँ | | tweetnacl | 15 KB | Pure JS | Curve25519, Ed25519, XSalsa20-Poly1305 | हाँ (original NaCl audit) | mostly, ChaCha20 नहीं | | crypto-js | 50 KB | Pure JS | AES-CBC, SHA, HMAC, PBKDF2 | कोई current audit नहीं | नहीं, 2023 से unmaintained | | node:crypto | 0 KB (Node native) | Node native (OpenSSL) | Comprehensive | हाँ (OpenSSL) | हाँ |

libsodium.js: Swiss Army Knife

libsodium.js (libsodium का Emscripten-compiled build) default pick है जब Web Crypto पर्याप्त नहीं है। यह XChaCha20-Poly1305, Ed25519, X25519, Argon2id, BLAKE2b, और streaming AEAD के लिए crypto_secretstream API cover करता है। WASM build typical hardware पर native libsodium speed के roughly 50-70% पर run करता है।

import _sodium from 'libsodium-wrappers';
await _sodium.ready;
const sodium = _sodium;

const key = sodium.crypto_secretstream_xchacha20poly1305_keygen();
const { state, header } = sodium.crypto_secretstream_xchacha20poly1305_init_push(key);
const chunk = sodium.crypto_secretstream_xchacha20poly1305_push(
  state, new Uint8Array([1,2,3]), null,
  sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE
);

Streaming API large file transfers के लिए killer feature है। आप 5 GB file को chunk by chunk बिना पूरी memory में load किए encrypt कर सकते हैं, और हर chunk अपना authentication tag carry करता है इसलिए corruption per chunk detect होती है, सिर्फ end में नहीं।

Trade-offs: 200 KB WASM ship करना बहुत है। Dynamic imports (await import('libsodium-wrappers')) इस्तेमाल करें ताकि library सिर्फ तब load हो जब encryption actually ज़रूरी हो। Sumo build (सभी algorithms includes) 600 KB+ है; extras ज़रूरी न हों तो default build से stick करें।

@noble: छोटा, Audited, Modern

Paul Miller का @noble family (@noble/ciphers, @noble/curves, @noble/hashes) pure-JavaScript crypto के लिए current best-in-class है। Cure53 (ciphers, 2023) और Trail of Bits (curves, 2022) द्वारा audited, zero dependencies, tree-shakeable, TypeScript-native।

import { gcm } from '@noble/ciphers/aes';
import { randomBytes } from '@noble/ciphers/webcrypto';

const key = randomBytes(32);
const nonce = randomBytes(12);
const ciphertext = gcm(key, nonce).encrypt(plaintext);

@noble WASM इस्तेमाल नहीं करता, इसलिए bundle impact छोटा है (ciphers के लिए 8 KB)। Bulk AES-GCM के लिए libsodium के WASM से 30-50% slower है, लेकिन अधिकांश transfer scenarios के लिए पर्याप्त। Pure-JS approach का मतलब है यह browsers, Node, Deno, Bun, और React Native में native module concerns के बिना identically काम करता है।

@noble तब इस्तेमाल करें जब bundle size matter करे, tree-shakeable pure-JS library चाहिए, या ऐसे platform पर हों जहाँ WASM rough edges रखता है।

tweetnacl: Minimalist

tweetnacl-js Daniel J. Bernstein की TweetNaCl C library को JavaScript में port करता है। 15 KB gzipped। Curve25519 key exchange, Ed25519 signatures, और XSalsa20-Poly1305 authenticated encryption cover करता है। Original NaCl effort के हिस्से के रूप में audited, हालाँकि recently नहीं।

import nacl from 'tweetnacl';

const key = nacl.randomBytes(32);
const nonce = nacl.randomBytes(24);
const ciphertext = nacl.secretbox(plaintext, nonce, key);

API deliberately tiny है: अगर NaCl से ज़्यादा चाहिए (जैसे non-JS systems के साथ interop के लिए AES-GCM), तो और देखें। Pure NaCl-protocol apps के लिए tweetnacl अभी भी reasonable choice है, हालाँकि @noble/ciphers plus @noble/curves more current maintenance के साथ same ground cover करते हैं।

crypto-js: नए Code के लिए इस्तेमाल न करें

crypto-js ने 2015 में browser crypto पर राज किया। 2026 में यह liability है। Last meaningful release 2021 था (4.1.1); repo effectively 2023 में archive हो गया। यह passwords से keys derive करने के लिए insecure scheme (OpenSSL के EVP_BytesToKey-style) के साथ AES-CBC default करता है जो MD5 के कुछ rounds से keys derive करता है। CVE-2023-46233 ने weak PBKDF2 defaults flag किए।

अगर आप legacy code maintain कर रहे हैं जो crypto-js इस्तेमाल करता है, @noble/ciphers या Web Crypto पर migrate करना straightforward है और effort के लायक है। 2026 में fresh start करें तो crypto-js skip करें।

Server Code के लिए node:crypto

Node का built-in crypto module OpenSSL wrap करता है और इस list पर सबसे broad algorithm coverage रखता है। Node 18+ पर, require('crypto').webcrypto Web Crypto-compatible API expose करता है, इसलिए isomorphic code server और client दोनों पर काम करता है।

import { createCipheriv, randomBytes } from 'crypto';

const key = randomBytes(32);
const iv = randomBytes(12);
const cipher = createCipheriv('aes-256-gcm', key, iv);
const ct = Buffer.concat([cipher.update(plaintext), cipher.final()]);
const tag = cipher.getAuthTag();

Browser में Web Crypto से encrypt किए files को server-side decrypt करने के लिए, यह cleanest path है।

Real File Encryption पर Performance

MacBook Air M2 पर 100 MB buffer को AES-256-GCM से encrypt करने के benchmarks:

  • Web Crypto API (Chrome 120): 340 ms (hardware-accelerated)
  • Web Crypto API (Safari 17): 280 ms (Apple Silicon पर hardware-accelerated)
  • libsodium.js WASM: 420 ms
  • @noble/ciphers: 1,850 ms (pure JS में कोई hardware acceleration नहीं)
  • tweetnacl (XSalsa20): 1,200 ms
  • node:crypto: 180 ms (native OpenSSL)

Takeaway: Web Crypto AES-NI इस्तेमाल करने से large files जीतता है। Pure JS small payloads के लिए ठीक है लेकिन multi-gigabyte transfers पर seconds add करता है। 5 GB upload के लिए, Web Crypto और @noble/ciphers के बीच encryption time में 2 minutes versus 10 minutes का difference हो सकता है।

Password Hashing: Argon2 ज़रूरी है

PBKDF2 table stakes है लेकिन Argon2id बेहतर है। Options:

  • argon2-browser: WASM-compiled reference implementation, 200 KB
  • @noble/hashes: pure-JS Argon2id, 15 KB, slower लेकिन pure
  • libsodium.js: crypto_pwhash से Argon2id, 200 KB लेकिन अगर libsodium already है तो आपके पास है

Browser contexts में password-derived encryption keys के लिए कम से कम 3 iterations, 64 MiB memory, और 4 parallelism के साथ Argon2id इस्तेमाल करें (OWASP 2024 guidance)।

अपने Stack के लिए चुनाव

  • AES-GCM encryption के साथ simple file transfer build कर रहे हैं: Web Crypto directly इस्तेमाल करें, कोई library नहीं। HexaTransfer यही pattern follow करता है।
  • ChaCha20-Poly1305 या streaming AEAD चाहिए: libsodium.js।
  • WASM के बारे में paranoid हैं या constrained bundlers पर ship करते हैं: @noble/ciphers + @noble/curves।
  • NaCl-protocol keys इस्तेमाल कर रहे हैं: @noble या libsodium, crypto-js नहीं।
  • crypto-js से migrate कर रहे हैं: bundle size matter करे तो @noble पर जाएं, नहीं तो libsodium.js।
  • Post-quantum signatures या KEM चाहिए: अभी कोई mature JS library नहीं; @noble/post-quantum check करें (early 2026 तक pre-release)।

Audit और Maintenance Signals

Crypto library adopt करने से पहले check करें:

  • Last commit date (18 महीने से ज़्यादा stale कुछ भी risky है)
  • Public audit reports (Cure53, Trail of Bits, NCC Group)
  • Unresolved security issues के लिए issue tracker
  • Dependency count (कम = smaller attack surface)
  • npm weekly downloads (ज़्यादा = code पर ज़्यादा नज़रें)

JavaScript ecosystem में supply-chain incidents (event-stream, ua-parser-js, colors) हुए हैं जो minimal dependencies को एक security property बनाते हैं। Zero runtime dependencies वाली crypto libraries (@noble family, tweetnacl) उन्हें end-to-end audit करना आसान है जो polyfills और utilities pull करती हैं उनसे।

hexatransfer.com पर आज़माएं — मुफ्त, बिना अकाउंट, 10 GB तक।

एंड-टू-एंड एन्क्रिप्शन के साथ बड़ी फ़ाइलें सुरक्षित रूप से भेजें

एंड-टू-एंड एन्क्रिप्शन के साथ 10 GB तक की फ़ाइलें मुफ़्त में ट्रांसफ़र करें। अकाउंट की आवश्यकता नहीं। अपलोड से पहले आपकी फ़ाइलें ब्राउज़र में एन्क्रिप्ट की जाती हैं — कोई और उन्हें पढ़ नहीं सकता।

फ़ाइल भेजें