Skip to content

Latest commit

 

History

History
230 lines (148 loc) · 7.11 KB

File metadata and controls

230 lines (148 loc) · 7.11 KB

This is a Next.js project bootstrapped with create-next-app.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.

This project uses next/font to automatically optimize and load Geist, a new font family for Vercel.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

Secure Health Record Encryption System

Welcome to the Secure Health Record Encryption System, a final-year Computer Science BSc project designed to provide a secure platform for encrypting and decrypting health records using the AES-256 algorithm. This application is tailored for small clinics to manage sensitive patient data securely. This README provides a step-by-step guide to set up, run, and understand the project.


Table of Contents


Project Overview

This project is a web-based application built with Next.js (frontend) and FastAPI (backend) to:

  • Encrypt health records using AES-256 encryption.
  • Store encrypted files in a MySQL database.
  • Allow users to decrypt and download files in .docx or .pdf format.
  • Provide a user-friendly dashboard with educational content and activity tracking.

The system is designed for clinic staff, ensuring data confidentiality and usability. It includes features like user authentication, file upload/decryption, and a modern UI.


Prerequisites

Before setting up the project, ensure you have the following installed on your system:

  • Node.js (v18 or later) - Download
  • Python (v3.9 or later) - Download
  • MySQL Server (v8.0 or later) - Download
  • Git - Download
  • A code editor (e.g., VS Code)
  • Basic knowledge of command-line operations

Environment Setup

  1. Clone the Repository:
    git clone https://github.com/your-username/health-record-encryption.git
    cd health-record-encryption

Create a Virtual Environment (Python):On Windows:

python -m venv venv venv\Scripts\activate

Install Frontend and Backend Dependencies (see below).


Dependencies Installation

Backend (Python)

Navigate to the backend directory:

  • cd backend

Install required Python packages:

  • pip install -r requirements.txt

If requirements.txt doesn’t exist, create it with the following content and run the install command:

  • fastapi
  • uvicorn
  • sqlalchemy
  • mysql-connector-python
  • python-jose[cryptography]
  • python-multipart
  • pycryptodome
  • python-docx
  • reportlab

Frontend (Node.js)

  1. Navigate to the frontend directory:
  • cd frontend
  1. Install required Node.js packages:
  • npm install

Ensure the following dependencies are included (add to package.json if missing):

  • react-slick
  • slick-carousel
  • @radix-ui/react-tabs
  • @shadcn/ui (install via npx shadcn-ui@latest add [component])

Database Installation and Connection

Install MySQL

  1. Install MySQL Server and set up a database.
  2. Create a database named health_records:
  • CREATE DATABASE health_records;

Configure Database Connection

  1. Open backend/app/database.py.
  2. Update the database URL with your MySQL credentials:
  • SQLALCHEMY_DATABASE_URL = "mysql+mysqlconnector://:@localhost:3306/health_records"

Replace and with your MySQL username and password (e.g., root and your password). 3. Ensure the database tables are created automatically when the backend starts (handled by SQLAlchemy).

Running the Project

  1. Start the Backend: Activate the virtual environment (if not already active). Navigate to the backend directory and run:
  • uvicorn app.main:app --host 127.0.0.1 --port 8000 --reload

The backend will be available at http://127.0.0.1:8000.

  1. Start the Frontend: Navigate to the frontend directory and run:
    • npm run dev

The frontend will be available at http://localhost:3000.

  1. Access the Application: Open your browser and go to http://localhost:3000.

Register a new user (e.g., username: devintel, password: devintel, role: admin) or log in with existing credentials.

Testing the Application

Basic Testing

  1. Registration and Login: Navigate to http://localhost:3000/register, create a user, and log in at http://localhost:3000/login.

  2. File Upload: Go to the “Encrypt Files” tab on the dashboard.

Upload a small .txt or .docx file (e.g., test.txt).

Check the sidebar for an activity log entry (e.g., “Uploaded file: test.txt”).

  1. File Listing and Decryption: Navigate to the “Decrypt Files” tab. Verify the uploaded file appears in the list. Click “Decrypt” and download as .docx or .pdf.

Advanced Testing

Large File Upload: Test with a larger .docx file (e.g., 1MB) to ensure the LONGBLOB storage works. Error Handling: Try uploading an invalid file type or accessing the dashboard without logging in (should redirect to /login).

How Uploads Work

  1. Process: Users select a file (e.g., .txt, .docx) via the “Encrypt Files” tab.

The frontend sends the file to the /files/upload endpoint using a POST request with multipart/form-data.

The backend:

Reads the file content. Generates a random AES-256 key and IV (initialization vector). Encrypts the file using AES in CBC mode. Stores the encrypted data, IV, and key in the files table of the MySQL database.

  1. Storage: Encrypted data is stored as a LONGBLOB to handle large files. The filename, user ID, IV, and encryption key are also saved for decryption.

  2. Security: Encryption ensures data confidentiality. User authentication restricts access to authorized users only.