# chandhanredd/secure-file-storage-using-hybrid-cryptography architecture

> Architecture diagram of the GitHub repository chandhanredd/secure-file-storage-using-hybrid-cryptography, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chandhanredd/secure-file-storage-using-hybrid-cryptography
- Repository: https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography

## Overview

##### What this project is (type + purpose)
From the README + file tree, this is a **Python application** that provides **secure cloud file storage using hybrid cryptography**.

“Hybrid cryptography” in this context almost certainly means:
- **Symmetric encryption** (fast; e.g., AES) for the file contents, and
- **Asymmetric encryption** (e.g., RSA) for encrypting the symmetric key (and possibly IV/metadata) so only an authorized user can decrypt.

The presence of:
- `client_secrets.json` + `token_drive_v3.pickle` strongly indicates **Google Drive API OAuth** integration.
- Files like `Encrypt.py`, `Decrypt.py`, `IVsKeys.py` suggest a clear separation of encryption/decryption and key/IV handling.
- `app.py`, `Main.py`, `demo.py`, `test.py` suggest there may be multiple entrypoints: a web app (likely Flask) and/or CLI demo scripts.

- A **local client app** that does crypto locally
- A **cloud storage backend** (Google Drive) that stores only ciphertext + encrypted keys/metadata
- An **auth layer** (Google OAuth) enabling Drive access

##### Core crypto layer
- `Encrypt.py` — file encryption pipeline (symmetric encryption + packaging)
- `Decrypt.py` — inverse pipeline
- `IVsKeys.py` — generation/loading/storing IVs + keys; possibly RSA keypair handling

##### Application orchestration / UX
- `Main.py` — likely primary controller for the flow (select file → encrypt → upload; download → decrypt)
- `app.py` — likely a web interface/API endpoint layer (common filename for Flask apps)
- `demo.py`, `test.py` — demonstration/testing entrypoints

##### Cloud integration
- `googlee.py` — likely wraps Google Drive operations (upload, download, list, auth)
- `client_secrets.json` — OAuth client credentials (Google API)
- `token_drive_v3.pickle` — cached OAuth tokens for Drive API access

##### Supporting utilities
- `dataProcessing.py` — file chunking, encoding/decoding, metadata formatting, etc.
- `Threads.py` — concurrency for encrypting/uploading/downloading (e.g., chunk uploads)

##### Data artifacts (what moves through the system)
- `Original.txt` → plaintext input example
- `Output.txt` → ciphertext output example (or decrypted output depending on flow)

##### Local Python Application Container
- “UI Layer” (CLI via `Main.py` and/or Web via `app.py`)
- “Crypto Engine” (`Encrypt.py`, `Decrypt.py`, `IVsKeys.py`)
- “Drive Client” (`googlee.py` + Google API SDK)
- “Processing + Concurrency” (`dataProcessing.py`, `Threads.py`)
- “Local Credential Store” (`token_drive_v3.pickle`, `client_secrets.json`)

##### Google Cloud Container
- **Google Drive Storage** (encrypted file objects)
- “Drive Metadata” (filenames, file IDs, any stored key blob)

Important detail to be explicit about:
- **Encryption happens locally**; Google Drive only sees ciphertext.
- OAuth token enables Drive access but does **not** grant plaintext access without keys.

- `app.py` / `Main.py`
**Role:** request handler / workflow orchestration
**Calls into:** encryption/decryption, Drive upload/download

- `Encrypt.py`
**Role:** generate session key/IV, encrypt file data
**Depends on:** `IVsKeys.py`, `dataProcessing.py` (likely)

- `Decrypt.py`
**Role:** retrieve encrypted key blob, decrypt session key, decrypt file data
**Depends on:** `IVsKeys.py`, `dataProcessing.py`

- `IVsKeys.py`
**Role:** key generation + storage format (symmetric key, IV, RSA keys)
**Outputs:** “Encrypted session key blob” and/or key files in a local store

- `googlee.py`
**Role:** Google Drive operations (auth, upload, download, list)
**Inputs/Outputs:** file bytes + metadata, file IDs

- `Threads.py`
**Role:** parallelize heavy operations (chunk encryption / chunk upload)

- `dataProcessing.py`
**Role:** chunking, buffering, file IO, base64/serialization, packaging metadata (e.g., `[ciphertext, encrypted_key, iv]`)

- Orchestrator → Encrypt/Decrypt
- Encrypt/Decrypt ↔ IVsKeys
- Encrypt/Decrypt ↔ dataProcessing
- Orchestrator → googlee
- googlee ↔ Google Drive API

##### `Encrypt.py`
- generates **symmetric key (K)** and **IV**
- encrypts file → **ciphertext C**
- encrypts K (and maybe IV) with **asymmetric public key** → **encKey**
##### `googlee.py` uploads
- ciphertext C (as the stored file)
- encKey + IV + metadata (either as a separate file or embedded metadata)

- “Encrypted File Blob (C)”
- “Encrypted Key Blob (encKey + IV + metadata)”

##### `Decrypt.py`
- decrypts encKey with private key → K
- decrypts ciphertext C with K and IV → plaintext

##### Architectural patterns to highlight (because they’re implied by structure)
- **Local cryptographic boundary:** all encryption/decryption is local; cloud is untrusted storage.
- **Hybrid encryption pattern:** file encrypted with symmetric key; symmetric key protected by asymmetric crypto.
- **Adapter/Client wrapper pattern:** `googlee.py` is an adapter over Google Drive SDK.
- **Pipeline + utilities:** `dataProcessing.py` and `Threads.py` imply “process in chunks” and “parallelize”.

If `Threads.py` is used for chunking and multi-part uploads, call that out as:
- “Chunk Encrypt → Chunk Upload” parallel pipeline.

Participants:
- User
- Main/app
- Encrypt/Decrypt
- IVsKeys
- googlee (Drive client)
- Google OAuth
- Google Drive

Messages should include payload labels: K, IV, C, encKey.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% =========================
    %% System Context (C4-ish)
    %% =========================
    subgraph "System Context"
        U["User"]:::external

        subgraph "Secure File Storage App (Python)"
            APP_SYS["Local Application"]:::boundary
        end

        OAUTH["Google OAuth / Identity"]:::external
        DRIVE["Google Drive (Cloud Storage)"]:::external
    end

    U -->|"select_file/retrieve_file"| APP_SYS
    APP_SYS -->|"oauth_consent+token_exchange"| OAUTH
    APP_SYS -->|"drive_api_calls"| DRIVE

    %% =========================
    %% Container Diagram (Runtime)
    %% =========================
    subgraph "Container View (Runtime Boundaries)"
        direction TB

        subgraph "Local Python Application (Trusted Crypto Boundary)"
            direction TB

            subgraph "Entrypoints / UX"
                direction TB
                MAIN["Main.py (CLI Workflow)"]:::orchestrator
                WEB["app.py (Web UI/API)"]:::orchestrator
                DEMO["demo.py (Demo Entrypoint)"]:::orchestrator2
                TEST["test.py (Test Entrypoint)"]:::orchestrator2
            end

            subgraph "Workflow Orchestration"
                direction TB
                ORCH["Orchestration Layer (Controller Flow)"]:::orchestrator
            end

            subgraph "Crypto Engine (Hybrid Cryptography)"
                direction TB
                ENC["Encrypt.py (Symmetric Encrypt + Package)"]:::crypto
                DEC["Decrypt.py (Unpackage + Symmetric Decrypt)"]:::crypto
                IVKEY["IVsKeys.py (IV/Key Mgmt + Asymmetric Key Handling)"]:::crypto
            end

            subgraph "Utilities (Pipeline Helpers)"
                direction TB
                DP["dataProcessing.py (Chunking/IO/Packaging)"]:::util
                TH["Threads.py (Concurrency Helpers)"]:::util
            end

            subgraph "Cloud Integration"
                direction TB
                GDRV["googlee.py (Google Drive API Adapter)"]:::cloud
                CREDS[(OAuth Client Credentials\nclient_secrets.json)]:::store
                TOK[(Cached OAuth Token\ntoken_drive_v3.pickle)]:::store
                REQS["requirements.txt (Dependencies)"]:::meta
                DOCS["README.md (Docs)"]:::meta
            end

            subgraph "Local Files (Artifacts)"
                direction TB
                INFILE[(Original.txt\nPlaintext Input)]:::storePlain
                OUTFILE[(Output.txt\nCiphertext/Decrypted Output)]:::storePlain
            end
        end

        subgraph "Google Cloud (Untrusted Storage)"
            direction TB
            DRIVE_STORE[(Google Drive Storage)]:::db
            C_OBJ[(Encrypted File Blob C)]:::db2
            K_OBJ[(Encrypted Key Blob\nencKey + IV + metadata)]:::db2
        end
    end

    %% =========================
    %% Component Dependencies / Flows
    %% =========================

    %% Entrypoints -> Orchestrator
    MAIN -->|"invoke_flow"| ORCH
    WEB -->|"http_requests"| ORCH
    DEMO -->|"demo_flow"| ORCH
    TEST -->|"test_flow"| ORCH

    %% Input/Output
    U -->|"PLAINTEXT_read"| INFILE
    ORCH -->|"read_plaintext"| INFILE
    DEC -->|"write_plaintext"| OUTFILE
    ENC -->|"optional_write_ciphertext"| OUTFILE

    %% Orchestrator -> Crypto
    ORCH -->|"encrypt_request"| ENC
    ORCH -->|"decrypt_request"| DEC

    %% Crypto <-> Key/IV mgmt and utilities
    ENC -->|"generate_K+IV"| IVKEY
    ENC -->|"chunk/package"| DP
    ENC -.->|"parallelize_chunks"| TH

    DEC -->|"load_private_key+unwrap_encKey"| IVKEY
    DEC -->|"unpack/decode"| DP
    DEC -.->|"parallelize_chunks"| TH

    DP -.->|"thread_pool/helpers"| TH

    %% Orchestrator -> Drive Adapter
    ORCH -->|"upload/download_ops"| GDRV

    %% Drive adapter auth and token usage
    GDRV -->|"read_client_credentials"| CREDS
    GDRV -->|"read_refresh_tokens"| TOK

    %% Drive adapter -> external systems
    GDRV -->|"OAuth_token_exchange"| OAUTH
    GDRV -->|"Drive_API_v3_calls"| DRIVE_STORE

    %% Upload data flows (explicit plaintext/ciphertext boundary)
    INFILE -->|"PLAINTEXT_bytes"| ENC
    ENC -->|"CIPHERTEXT_C"| GDRV
    ENC -->|"encKey+IV+metadata"| GDRV

    GDRV -->|"upload_ciphertext"| C_OBJ
    GDRV -->|"upload_encrypted_session_key"| K_OBJ

    %% Download data flows
    C_OBJ -->|"download_ciphertext"| GDRV
    K_OBJ -->|"download_key_blob"| GDRV
    GDRV -->|"CIPHERTEXT_C+encKey_blob"| DEC
    DEC -->|"PLAINTEXT_bytes"| OUTFILE

    %% Data in Drive grouped under storage
    DRIVE_STORE -->|"stores"| C_OBJ
    DRIVE_STORE -->|"stores"| K_OBJ

    %% Dependencies callouts (from requirements)
    REQS -.->|"Google_API_SDK+Crypto_Libs"| GDRV
    REQS -.->|"Crypto_Primitives"| ENC
    REQS -.->|"Crypto_Primitives"| DEC
    DOCS -.->|"usage_notes"| MAIN
    DOCS -.->|"setup_oauth"| CREDS

    %% =========================
    %% Sequence Diagram (Bonus)
    %% =========================
    subgraph "Sequence (Upload + Download)"
        direction TB
        SEQNOTE["Order of operations: hybrid crypto stays local; only ciphertext+encKey stored in Drive"]:::note

        subgraph "Upload Encrypted File"
            direction TB
            SU1["1) User selects file"]:::seq
            SU2["2) Orchestrator calls Encrypt"]:::seq
            SU3["3) Encrypt: K,IV -> C; encKey=RSA(K[,IV])"]:::seq
            SU4["4) Drive Adapter uploads C + encKey/IV/metadata"]:::seq
        end

        subgraph "Download + Decrypt File"
            direction TB
            SD1["1) User requests file"]:::seq
            SD2["2) Drive Adapter downloads C + encKey blob"]:::seq
            SD3["3) Decrypt: RSA^-1(encKey)->K; AES^-1(C,K,IV)->plaintext"]:::seq
            SD4["4) Write Output.txt"]:::seq
        end
    end

    %% Tie sequence to components (vertical links)
    SU1 --> MAIN
    SU2 --> ORCH
    SU3 --> ENC
    SU4 --> GDRV

    SD1 --> MAIN
    SD2 --> GDRV
    SD3 --> DEC
    SD4 --> OUTFILE

    %% =========================
    %% Click Events (from mapping)
    %% =========================
    click ENC "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/Encrypt.py"
    click DEC "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/Decrypt.py"
    click IVKEY "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/IVsKeys.py"

    click MAIN "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/Main.py"
    click WEB "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/app.py"
    click DEMO "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/demo.py"
    click TEST "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/test.py"

    click GDRV "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/googlee.py"
    click CREDS "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/client_secrets.json"
    click TOK "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/token_drive_v3.pickle"

    click DP "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/dataProcessing.py"
    click TH "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/Threads.py"

    click INFILE "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/Original.txt"
    click OUTFILE "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/Output.txt"

    click REQS "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/requirements.txt"
    click DOCS "https://github.com/chandhanredd/secure-file-storage-using-hybrid-cryptography/blob/main/README.md"

    %% =========================
    %% Styles
    %% =========================
    classDef external fill:#f3f4f6,stroke:#111827,stroke-width:1px,color:#111827
    classDef boundary fill:#e0f2fe,stroke:#0284c7,stroke-width:2px,color:#0c4a6e
    classDef orchestrator fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e3a8a
    classDef orchestrator2 fill:#bfdbfe,stroke:#1d4ed8,stroke-width:1.5px,color:#1e3a8a
    classDef crypto fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#052e16
    classDef cloud fill:#ffedd5,stroke:#ea580c,stroke-width:2px,color:#7c2d12
    classDef util fill:#e5e7eb,stroke:#4b5563,stroke-width:1.5px,color:#111827
    classDef db fill:#fee2e2,stroke:#dc2626,stroke-width:2px,color:#7f1d1d
    classDef db2 fill:#fecaca,stroke:#ef4444,stroke-width:1.5px,color:#7f1d1d
    classDef store fill:#faf5ff,stroke:#7c3aed,stroke-width:1.5px,color:#2e1065
    classDef storePlain fill:#f5f3ff,stroke:#6d28d9,stroke-width:1.5px,color:#2e1065
    classDef meta fill:#f1f5f9,stroke:#334155,stroke-width:1.2px,color:#0f172a
    classDef note fill:#fff7ed,stroke:#c2410c,stroke-width:1.2px,color:#7c2d12
    classDef seq fill:#ffffff,stroke:#0f172a,stroke-width:1px,color:#0f172a
```
