Skip to content

SREENIDHIPAGIDIMARRI/LexCrypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” LexCrypt β€” Full-Stack Cryptography Vault

Military-grade AES-256 encryption, RSA key pairs, SHA-256 digital signatures β€” built with React.js + Node.js + Express + MongoDB.


πŸš€ Features

πŸ” AES-256 Encryption – Secure sensitive data ✍️ RSA-2048 Digital Signatures – Identity verification 🧾 SHA-256 Hashing – Tamper detection πŸ“ Secure file upload & vault system πŸ”‘ Authentication system (Login / Signup)


πŸ› οΈ Tech Stack

Layer Technology
Frontend React 18, React Router v6, Axios, Framer Motion, react-hot-toast
Backend Node.js, Express.js
Database MongoDB + Mongoose ODM
Auth JWT (jsonwebtoken) + bcryptjs
Encryption (server) Node.js crypto β€” AES-256-CBC, PBKDF2-SHA256
Encryption (client) Web Crypto API β€” AES-CBC, PBKDF2, SHA-256
Security Helmet.js, CORS, express-rate-limit, express-validator

πŸ—οΈ Architecture

lexcrypt/
β”œβ”€β”€ backend/                  ← Node.js + Express + MongoDB API
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ server.js         ← Entry point
β”‚   β”‚   β”œβ”€β”€ app.js            ← Express app (CORS, Helmet, rate limiting)
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   └── db.js         ← Mongoose connection
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   β”œβ”€β”€ user.model.js       ← User schema (bcrypt password hashing)
β”‚   β”‚   β”‚   β”œβ”€β”€ vaultFile.model.js  ← Encrypted file records
β”‚   β”‚   β”‚   └── signature.model.js  ← Digital signature records
β”‚   β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”‚   └── auth.middleware.js  ← JWT Bearer token verification
β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.controller.js       ← Signup, login, getMe, saveKeys
β”‚   β”‚   β”‚   β”œβ”€β”€ vault.controller.js      ← Upload, list, decrypt, delete
β”‚   β”‚   β”‚   β”œβ”€β”€ crypto.controller.js     ← Text encrypt/decrypt
β”‚   β”‚   β”‚   └── signature.controller.js  ← Sign, verify, list, delete
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.routes.js
β”‚   β”‚   β”‚   β”œβ”€β”€ vault.routes.js
β”‚   β”‚   β”‚   β”œβ”€β”€ crypto.routes.js
β”‚   β”‚   β”‚   └── signature.routes.js
β”‚   β”‚   └── utils/
β”‚   β”‚       β”œβ”€β”€ crypto.utils.js   ← AES-256-CBC, PBKDF2, SHA-256, signatures
β”‚   β”‚       └── jwt.utils.js      ← Token signing + response helper
β”‚   β”œβ”€β”€ uploads/              ← Static file storage
β”‚   β”œβ”€β”€ .env.example
β”‚   └── package.json
β”‚
└── frontend/                 ← React.js SPA
    β”œβ”€β”€ public/
    β”‚   └── index.html
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ index.js          ← ReactDOM entry
    β”‚   β”œβ”€β”€ App.jsx           ← Router + AuthProvider + Toaster
    β”‚   β”œβ”€β”€ api/
    β”‚   β”‚   └── index.js      ← Axios instance + JWT interceptor + all API calls
    β”‚   β”œβ”€β”€ context/
    β”‚   β”‚   └── AuthContext.jsx  ← Global auth state (useReducer)
    β”‚   β”œβ”€β”€ utils/
    β”‚   β”‚   └── crypto.js     ← Client-side AES-256-CBC, SHA-256, key generation
    β”‚   β”œβ”€β”€ components/
    β”‚   β”‚   β”œβ”€β”€ ui/index.jsx       ← Button, Input, Card, Badge, Alert, Spinner…
    β”‚   β”‚   └── layout/index.jsx   ← MatrixCanvas, Navbar, ProtectedRoute
    β”‚   β”œβ”€β”€ pages/
    β”‚   β”‚   β”œβ”€β”€ Landing.jsx
    β”‚   β”‚   β”œβ”€β”€ Signup.jsx
    β”‚   β”‚   β”œβ”€β”€ Login.jsx
    β”‚   β”‚   β”œβ”€β”€ Vault.jsx        ← 4-step key wizard
    β”‚   β”‚   β”œβ”€β”€ Upload.jsx       ← File encrypt/vault/decrypt with modal auth
    β”‚   β”‚   β”œβ”€β”€ Crypto.jsx       ← Text encrypt/decrypt via API
    β”‚   β”‚   └── Signatures.jsx   ← Sign, verify, log via API
    β”‚   └── styles/
    β”‚       └── globals.css
    β”œβ”€β”€ .env
    └── package.json

πŸ”’ Security Architecture

Layer What's protected How
Transport All API calls HTTPS (production) + CORS whitelist
Authentication Every protected route JWT Bearer tokens (7-day expiry)
Passwords User passwords in DB bcrypt (12 rounds)
Rate Limiting All routes 200 req/15min global; 20 req/15min auth
Headers XSS, clickjacking etc. Helmet.js
File Encryption Files in MongoDB AES-256-CBC, PBKDF2-SHA256, random IV per file
Integrity Every vault file SHA-256 hash stored at encrypt time, verified at decrypt time
Authentication File decryption Private key required, normalised comparison
Non-repudiation Vault files SHA-256(hash:userId:fileId) digital signature
Private keys User's private key Never sent to server β€” session-only (sessionStorage)

πŸš€ Setup & Installation

Prerequisites

  • Node.js β‰₯ 18
  • MongoDB (local or MongoDB Atlas)
  • npm or yarn

1. Backend Setup

cd lexcrypt/backend

# Install dependencies
npm install

# Configure environment
cp .env.example .env
# Edit .env:
#   MONGO_URI=mongodb://localhost:27017/lexcrypt
#   JWT_SECRET=your_minimum_32_char_secret_here
#   PORT=5000

# Start development server
npm run dev
# β†’ LexCrypt Backend running on port 5000
# β†’ MongoDB: connected

2. Frontend Setup

cd lexcrypt/frontend

# Install dependencies
npm install

# Start React development server
npm start
# β†’ Opens http://localhost:3000

3. MongoDB Atlas (Production)

Replace MONGO_URI in .env with your Atlas connection string:

MONGO_URI=mongodb+srv://<user>:<password>@cluster0.xxxxx.mongodb.net/lexcrypt?retryWrites=true&w=majority

⚑ Cryptographic Flow

File Encryption

User uploads file
  β†’ FileReader reads bytes as base64
  β†’ SHA-256(base64) computed client-side β†’ stored as integrity hash
  β†’ AES secret = PBKDF2-SHA256(publicKey, salt, 100000 iterations)
  β†’ AES-256-CBC encrypts base64 with random IV
  β†’ { cipherText, iv, sha256Hash } sent to backend API (JWT auth)
  β†’ Backend generates digital signature: SHA-256(hash:userId:fileId)
  β†’ All stored in MongoDB VaultFile document

File Decryption

User clicks Decrypt
  β†’ Private key modal opens, shows SHA-256 fingerprint + digital signature
  β†’ User enters private key
  β†’ Frontend: normaliseKey(input) === normaliseKey(sessionPrivKey)  ← auth check
  β†’ POST /api/vault/decrypt/:id { privateKey }
  β†’ Backend: verifySignature(hash, userId, fileId, storedSig)  ← sig check
  β†’ Backend: AES-256-CBC decrypt with stored keySecret
  β†’ Backend: SHA-256(decrypted) === storedHash  ← integrity check
  β†’ { decryptedContent, sigValid, integrityOk } returned
  β†’ Client reconstructs file bytes, shows preview + download

Text Encryption (Crypto page)

POST /api/crypto/encrypt { plainText, publicKey }
  β†’ Server: secret = SHA-256(publicKey)
  β†’ Server: { cipherText, iv } = AES-256-CBC(plainText, PBKDF2(secret))
  β†’ Server stores keySecret on user document
  β†’ Returns { cipherText, iv, sha256, algorithm }

POST /api/crypto/decrypt { cipherText, iv, privateKey }
  β†’ Server retrieves keySecret from user.keySecret
  β†’ Server: AES-256-CBC decrypt
  β†’ Returns { plainText }

πŸ“‘ API Reference

Auth β€” /api/auth

Method Endpoint Auth Body Description
POST /signup ❌ { firstName, lastName, username, email, password } Register new user
POST /login ❌ { identifier, password } Login, returns JWT
GET /me βœ… JWT β€” Get current user
PUT /keys βœ… JWT { publicKey, keySecret, vaultName } Save vault keys

Vault β€” /api/vault

Method Endpoint Auth Body Description
POST /upload βœ… JWT { originalName, mimeType, size, cipherText, iv, sha256Hash, publicKey } Upload encrypted file
GET /files βœ… JWT β€” List all vault files (no cipherText)
POST /decrypt/:id βœ… JWT { privateKey } Decrypt a vault file
DELETE /files/:id βœ… JWT β€” Delete vault file

Crypto β€” /api/crypto

Method Endpoint Auth Body Description
POST /encrypt βœ… JWT { plainText, publicKey } AES-256 encrypt text
POST /decrypt βœ… JWT { cipherText, iv, privateKey } AES-256 decrypt text

Signatures β€” /api/signatures

Method Endpoint Auth Body Description
POST /sign βœ… JWT { content, label } SHA-256 sign document
POST /verify βœ… JWT { content, hash } Verify SHA-256 hash
GET / βœ… JWT β€” List all signatures
DELETE /:id βœ… JWT β€” Delete signature

πŸ—’οΈ Notes

  • Private keys are never sent to the server. They live only in sessionStorage during the browser session. Once you close the tab, they're gone β€” save them!
  • The AES key is derived from SHA-256(publicKey) via PBKDF2 with 100,000 iterations and a fixed salt. Both frontend and backend use the same derivation so they always produce the same AES key.
  • Each file gets a unique random IV for AES-CBC β€” even encrypting the same file twice produces different ciphertext.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors