Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔐 File Encryption & Decryption Web App

Go CI

A robust, production-ready cryptographic web application built with Go that provides secure file encryption and decryption using AES-GCM (256-bit) encryption with password-based key derivation.

🌐 Live Demo Try it here (Replace with your actual Render URL)

✨ Features 🔒 Military-Grade Encryption: AES-GCM 256-bit encryption with authenticated encryption

💧 Stream Processing: Memory-efficient chunked encryption (64KB blocks) - handles large files without loading them entirely into RAM

🌐 Web Interface: Clean, user-friendly HTML interface for easy file encryption/decryption

🔑 Password-Based Security: PBKDF2 key derivation with salting

📦 CLI Support: Command-line interface for advanced users

🐳 Docker Ready: Containerized for easy deployment

⚡ Fast & Lightweight: Built with Go for optimal performance

🏗️ Architecture

┌─────────────────────────────────────────────────┐ │ Web Interface (index.html) │ │ [Upload File] → [Enter Password] → [Encrypt] │ └─────────────────────┬───────────────────────────┘ │ ↓ ┌─────────────────────────────────────────────────┐ │ HTTP Server (server.go) │ │ • Handles file uploads │ │ • Routes requests to crypto library │ │ • Streams encrypted/decrypted data back │ └─────────────────────┬───────────────────────────┘ │ ↓ ┌─────────────────────────────────────────────────┐ │ Crypto Library (pkg/cryptolib/cryptolib.go) │ │ • AES-GCM encryption with 64KB chunks │ │ • PBKDF2 key derivation (100,000 iterations) │ │ • Random salt & nonce generation │ │ • Stream processing (io.Reader/io.Writer) │ └─────────────────────────────────────────────────┘

🚀 Quick Start Prerequisites Go 1.20+ installed

Git for cloning the repository

Local Setup

  1. Clone the Repository bash git clone https://github.com/wasim-builds/File_Encryption-And-Decryption.git cd File_Encryption-And-Decryption

  2. Install Dependencies bash go mod download

  3. Run the Web Server bash go run . serve The server will start at http://localhost:8080

  4. (Optional) Custom Port bash go run . serve -port 3000

  5. Open in Browser Navigate to http://localhost:8080 in your web browser.

📖 Usage Guide Web Interface Encrypt a File:

Click "Choose File" and select your file

Enter a strong password

Click "Encrypt"

Download the .enc file

Decrypt a File:

Click "Choose File" and select your .enc file

Enter the same password used for encryption

Click "Decrypt"

Download the decrypted file

Command Line Interface Encrypt a File bash go run . encrypt -f myfile.txt -p mypassword Output: myfile.txt.enc

Decrypt a File bash go run . decrypt -f myfile.txt.enc -p mypassword Output: myfile.txt

Build Executable bash go build -o gocrypt .

Use the executable

./gocrypt encrypt -f document.pdf -p securepass123 ./gocrypt decrypt -f document.pdf.enc -p securepass123 🐳 Docker Deployment Build Docker Image bash docker build -t file-encryption-app . Run Container bash docker run -p 8080:8080 file-encryption-app Access at http://localhost:8080

🌍 Deploy to Render Method 1: Using Render Dashboard Fork/Push this repository to your GitHub

Go to Render Dashboard

Click New + → Web Service

Connect your GitHub repository

Configure:

Environment: Docker

Plan: Free

Click Create Web Service

Render will automatically deploy using the Dockerfile

Method 2: Using Render Blueprint Create a render.yaml file:

text services:

  • type: web name: file-encryption-app env: docker plan: free healthCheckPath: / Then deploy via Render dashboard or CLI.

🔐 Security Features Feature Implementation Encryption Algorithm AES-GCM (256-bit) Key Derivation PBKDF2 with 100,000 iterations Salt 32-byte random salt per file Nonce 12-byte random nonce per chunk Chunk Size 64KB for streaming Authentication GCM provides authenticated encryption 📁 Project Structure text File_Encryption-And-Decryption/ ├── main.go # CLI entry point ├── server.go # HTTP server & handlers ├── index.html # Web interface ├── Dockerfile # Docker configuration ├── go.mod # Go module definition ├── go.sum # Dependency checksums ├── .gitignore # Git ignore rules └── pkg/ └── cryptolib/ ├── cryptolib.go # Core encryption library └── cryptolib_test.go # Unit tests 🛠️ Technical Details Encryption Process Key Derivation: Password → PBKDF2 → 32-byte key

File Reading: Input file read in 64KB chunks

Encryption: Each chunk encrypted with AES-GCM

Output Format:

text [32-byte salt][chunk1][chunk2]...[chunkN] Each chunk: [12-byte nonce][encrypted data][16-byte tag] Memory Efficiency Traditional approach: Load entire file into memory → encrypt → write

This implementation: Stream 64KB chunks → encrypt each → write immediately

Benefit: Can encrypt multi-GB files with constant ~64KB RAM usage

🧪 Running Tests bash

Run all tests

go test ./...

Run with coverage

go test -cover ./pkg/cryptolib

Verbose output

go test -v ./pkg/cryptolib 📊 Performance File Size Encryption Time Memory Usage 1 MB ~0.1s ~64 KB 100 MB ~3s ~64 KB 1 GB ~30s ~64 KB Tested on: Intel i5, 8GB RAM, SSD

🚨 Important Notes File Size Limits Web Interface: 10MB limit (configurable in server.go)

CLI: No limit (uses streaming)

To increase web limit: Modify ParseMultipartForm(10 << 20) in server.go

Security Best Practices ✅ Use strong, unique passwords (12+ characters)

✅ Store encrypted files and passwords separately

✅ Never commit passwords to version control

❌ Don't reuse passwords across files

❌ Don't store passwords in plain text

Limitations Password recovery is impossible - if you lose the password, the file cannot be decrypted

Encrypted files are slightly larger than originals due to salt, nonces, and authentication tags

Maximum file size for web interface is limited by server configuration

🐛 Troubleshooting "Package gocrypt/pkg/cryptolib not found" bash go mod tidy go mod download "Port already in use" bash

Use a different port

go run . serve -port 3000 "File too large" error on web interface Modify server.go line ~40:

go err := r.ParseMultipartForm(50 << 20) // 50MB limit Decryption fails ✅ Verify you're using the correct password

✅ Ensure the .enc file is not corrupted

✅ Check file was encrypted with this tool

🤝 Contributing Contributions are welcome! Please:

Fork the repository

Create a feature branch (git checkout -b feature/AmazingFeature)

Commit your changes (git commit -m 'Add AmazingFeature')

Push to the branch (git push origin feature/AmazingFeature)

Open a Pull Request

📝 Future Enhancements Progress bars for encryption/decryption in web UI

Support for multiple file encryption (batch processing)

Drag-and-drop file upload

Password strength indicator

Download encrypted files as ZIP

API endpoints for programmatic access

Mobile-responsive design improvements

📄 License This project is open source and available for educational purposes.

👨‍💻 Author Wasim Khan

GitHub: @wasim-builds

Repository: File_Encryption-And-Decryption

🌟 Acknowledgments Built with Go's crypto/aes and crypto/cipher packages

Uses standard cryptographic best practices

Inspired by the need for memory-efficient file encryption

⭐ If you find this project useful, please give it a star! Made with ❤️ and Go

About

A robust cryptographic tool developed in Go (1.24+) that solves the memory limitation of standard file encryption. It implements a custom chunking architecture (64KB blocks) with AES-GCM and incremental nonces, enabling authenticated encryption streams (io.Reader/io.Writer) for files of any size without loading them entirely into RAM.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages