Secure File Sharing
with End-to-End Encryption

A cryptographically secure file storage and sharing system built in Go, featuring military-grade encryption, digital signatures, and zero-trust architecture.

AES-256
Encryption
RSA-2048
Key Exchange
HMAC
Integrity
DSA
Signatures

Security-First Features

Built with cryptographic best practices and zero-trust principles

End-to-End Encryption

All files encrypted with AES-256 before storage. Keys never leave your device.

  • Symmetric encryption with unique keys per file
  • RSA-2048 for secure key exchange
  • Zero-knowledge architecture

Secure File Sharing

Share files with cryptographically signed invitations and fine-grained access control.

  • Digitally signed invitations
  • Hierarchical sharing (transitive access)
  • Per-user encryption keys

Integrity Protection

HMAC authentication ensures tamper detection for all stored data.

  • Encrypt-then-MAC pattern
  • SHA-256 HMAC for all structures
  • Automatic integrity verification

Access Revocation

Instantly revoke access with automatic re-encryption of all file content.

  • Complete re-encryption on revocation
  • Updates all remaining users
  • Forward secrecy guaranteed

Efficient Storage

Files stored as encrypted linked lists for O(1) append operations.

  • Chunked file storage
  • Constant-time appends
  • Efficient for large files

Strong Authentication

Argon2 key derivation and PKI-based user authentication.

  • Argon2 password hashing
  • Public key infrastructure
  • Digital signature verification

System Architecture

A layered security architecture with cryptographic primitives at every level

graph TB subgraph UserLayer["User Management Layer"] InitUser["InitUser / GetUser"] RSAKeys["RSA Key Pairs"] Argon2["Argon2 Auth"] end subgraph FileLayer["File Storage Layer"] FileStruct["File Struct
Metadata + Keys"] Node["Node (Linked)
Encrypted Content"] Accessor["Accessor
Access Control"] AES["AES-CTR Encryption"] end subgraph SharingLayer["Sharing & Access Control Layer"] CreateInv["CreateInvitation"] AcceptInv["AcceptInvitation"] Revoke["RevokeAccess"] PKE["PKE + DSA"] end subgraph SecurityLayer["Security Layer - HMAC Integrity Protection"] EncryptMAC["Encrypt-then-MAC"] HMAC["HMAC-SHA256"] Tamper["Tamper Detection"] end UserLayer --> FileLayer FileLayer --> SharingLayer SharingLayer --> SecurityLayer style UserLayer fill:#3b82f6,stroke:#2563eb,stroke-width:2px,color:#fff style FileLayer fill:#8b5cf6,stroke:#7c3aed,stroke-width:2px,color:#fff style SharingLayer fill:#06b6d4,stroke:#0891b2,stroke-width:2px,color:#fff style SecurityLayer fill:#10b981,stroke:#059669,stroke-width:2px,color:#fff style InitUser fill:#60a5fa,stroke:#3b82f6,color:#0f172a style RSAKeys fill:#60a5fa,stroke:#3b82f6,color:#0f172a style Argon2 fill:#60a5fa,stroke:#3b82f6,color:#0f172a style FileStruct fill:#a78bfa,stroke:#8b5cf6,color:#0f172a style Node fill:#a78bfa,stroke:#8b5cf6,color:#0f172a style Accessor fill:#a78bfa,stroke:#8b5cf6,color:#0f172a style AES fill:#a78bfa,stroke:#8b5cf6,color:#0f172a style CreateInv fill:#22d3ee,stroke:#06b6d4,color:#0f172a style AcceptInv fill:#22d3ee,stroke:#06b6d4,color:#0f172a style Revoke fill:#22d3ee,stroke:#06b6d4,color:#0f172a style PKE fill:#22d3ee,stroke:#06b6d4,color:#0f172a style EncryptMAC fill:#34d399,stroke:#10b981,color:#0f172a style HMAC fill:#34d399,stroke:#10b981,color:#0f172a style Tamper fill:#34d399,stroke:#10b981,color:#0f172a

User Management Layer

Handles user registration, authentication, and key management with RSA and DSA key pairs.

Argon2 RSA-2048 DSA

File Storage Layer

Encrypted linked-list structure for efficient file storage and retrieval with per-node encryption.

AES-CTR Linked Lists UUID

Sharing Layer

Cryptographically secure invitation system with digital signatures and access control.

PKE Digital Signatures Access Control

Security Layer

HMAC integrity protection and encrypt-then-MAC pattern throughout the entire system.

HMAC-SHA256 Encrypt-then-MAC Zero-Trust

API Reference

Complete API documentation for all operations

InitUser

User Management
func InitUser(username string, password string) (*User, error)

Creates a new user account with secure key generation and encrypted storage.

Parameters

  • username: Unique username (must be non-empty)
  • password: Password for authentication (used for Argon2 key derivation)

Returns

  • Pointer to User struct with generated keys
  • Error if username exists or initialization fails

Security Features

  • Generates RSA-2048 key pair for encryption
  • Generates DSA key pair for digital signatures
  • Stores public keys in keystore
  • Encrypts user struct with Argon2-derived key
// Create a new user
user, err := InitUser("alice", "securePassword123")
if err != nil {
    log.Fatal("Failed to create user:", err)
}
fmt.Println("User created:", user.Username)

GetUser

User Management
func GetUser(username string, password string) (*User, error)

Authenticates and retrieves an existing user from encrypted storage.

Parameters

  • username: Username to authenticate
  • password: Password for verification

Returns

  • Pointer to authenticated User struct
  • Error if credentials invalid or user doesn't exist
// Authenticate existing user
user, err := GetUser("alice", "securePassword123")
if err != nil {
    log.Fatal("Authentication failed:", err)
}
fmt.Println("Logged in as:", user.Username)

StoreFile

File Management
func (userdata *User) StoreFile(filename string, content []byte) error

Stores a new file or overwrites existing file with encrypted content.

Parameters

  • filename: Name of the file (must be non-empty)
  • content: File content as byte array

Behavior

  • Creates new file if doesn't exist
  • Overwrites completely if exists
  • Encrypts with unique symmetric key
  • Protects with HMAC
// Store encrypted file
content := []byte("Secret document content")
err := user.StoreFile("document.txt", content)
if err != nil {
    log.Fatal("Failed to store file:", err)
}
fmt.Println("File stored securely")

LoadFile

File Management
func (userdata *User) LoadFile(filename string) ([]byte, error)

Retrieves and decrypts file content with automatic integrity verification.

Implementation

  • Traverses linked list backward from tail
  • Verifies HMAC for each node
  • Decrypts content with stored keys
  • Concatenates in correct order
// Load and decrypt file
content, err := user.LoadFile("document.txt")
if err != nil {
    log.Fatal("Failed to load file:", err)
}
fmt.Println("File content:", string(content))

AppendToFile

File Management
func (userdata *User) AppendToFile(filename string, content []byte) error

Efficiently appends content to existing file in O(1) time complexity.

Efficiency

  • O(1) operation - only accesses tail node
  • Creates new encrypted node
  • Links to previous tail
  • Updates file metadata pointer
// Efficiently append to file
newContent := []byte("\nAdditional content")
err := user.AppendToFile("document.txt", newContent)
if err != nil {
    log.Fatal("Failed to append:", err)
}
fmt.Println("Content appended successfully")

CreateInvitation

Sharing
func (userdata *User) CreateInvitation(filename string, recipientUsername string) (uuid.UUID, error)

Creates cryptographically secure invitation to share file access.

Security Process

  • Encrypts invitation with recipient's public key
  • Signs with sender's private signing key
  • Creates new accessor for direct shares (owner)
  • Reuses accessor for transitive shares (non-owner)

Returns

  • UUID of invitation for recipient
  • Error if file doesn't exist or recipient not found
// Share file with another user
inviteUUID, err := alice.CreateInvitation("document.txt", "bob")
if err != nil {
    log.Fatal("Failed to create invitation:", err)
}
fmt.Println("Invitation created:", inviteUUID)

AcceptInvitation

Sharing
func (userdata *User) AcceptInvitation(senderUsername string, invitationPtr uuid.UUID, filename string) error

Accepts invitation and adds shared file to user's namespace with verification.

Security Checks

  • Verifies digital signature from sender
  • Decrypts with user's private key
  • Validates invitation hasn't been revoked
  • Checks filename availability
// Accept shared file invitation
err := bob.AcceptInvitation("alice", inviteUUID, "shared-doc.txt")
if err != nil {
    log.Fatal("Failed to accept invitation:", err)
}
fmt.Println("File access granted")

RevokeAccess

Sharing
func (userdata *User) RevokeAccess(filename string, recipientUsername string) error

Revokes user access with complete re-encryption (owner only).

Revocation Process

  • Re-encrypts all file content with new keys
  • Moves all nodes to new UUIDs
  • Updates all remaining users' accessors
  • Deletes revoked user's accessor and invitation

Security Guarantees

  • Forward secrecy - old keys become useless
  • Immediate effect - no grace period
  • Revoked user cannot access any version
// Revoke user's access to file
err := alice.RevokeAccess("document.txt", "bob")
if err != nil {
    log.Fatal("Failed to revoke access:", err)
}
fmt.Println("Access revoked successfully")

Security Model

Defense-in-depth with multiple layers of cryptographic protection

Confidentiality

  • AES-256-CTR symmetric encryption
  • RSA-2048 public-key encryption
  • Unique keys per file and node
  • Zero-knowledge architecture

Integrity

  • HMAC-SHA256 for all structures
  • Encrypt-then-MAC pattern
  • Tamper detection on all reads
  • Cryptographic hashing (SHA-256)

Authentication

  • DSA digital signatures
  • Argon2 key derivation
  • Public key infrastructure
  • Signature verification on shares

Authorization

  • Owner-based access control
  • Explicit invitation system
  • Granular permission management
  • Secure revocation with re-encryption

Threat Model

🛡️

Datastore Adversary

Cannot read, modify, or meaningfully corrupt stored data

👤

Malicious Users

Cannot access files without proper authorization

🌐

Network Adversary

Cannot intercept or modify invitations in transit

Design Principles

Defense in Depth

Multiple security layers: encryption + HMAC + signatures

Zero Trust

All data verified before use, no implicit trust

Least Privilege

Users access only explicitly shared files

Key Isolation

Unique keys for each operation and file

Forward Security

Revocation renders old keys permanently useless

Fail Secure

All errors reject access, no unsafe fallbacks

Getting Started

Quick setup and installation guide

1

Clone Repository

git clone https://github.com/mananb77/file-sharing-system.git
cd file-sharing-system
2

Install Dependencies

go mod download
3

Run Tests

cd client_test
go test -v
4

Use in Your Code

import "github.com/mananb77/file-sharing-system/client"

// Create user
user, _ := client.InitUser("alice", "password123")

// Store file
user.StoreFile("secret.txt", []byte("confidential data"))

// Load file
content, _ := user.LoadFile("secret.txt")

Requirements

  • Go 1.18 or later
  • Unix-like OS (Linux, macOS)
  • Git for version control