Building Encrypz Android: Engineering a Zero-Knowledge Cloud Vault in Kotlin
How I architected a client-side cryptographic engine, pluggable Google Drive & SAF storage backends, and seamless in-app media playback in Kotlin and Jetpack Compose.
Cloud storage is convenient, but it comes with a fundamental trade-off: you have to trust the provider with your unencrypted data. Even when files are encrypted in transit and at rest, the provider holds the keys. I wanted a way to use everyday cloud storage like Google Drive without ever exposing my files, filenames, or folder structures to the cloud provider.
That goal led me to build Encrypz Android—an open-source, native Android application written in Kotlin and Jetpack Compose that brings client-side, zero-knowledge encryption to mobile. Here is a look under the hood at how I architected the cryptographic engine, storage backends, and user experience.
Designing the Client-Side Cryptographic Engine
The core rule of a zero-knowledge vault is simple: plaintext never leaves the device. To enforce this, I
built a dedicated cryptographic layer (com.encrypz.privacy.crypto.vault) that handles key
derivation, key management, file encryption, and path obfuscation locally before a single byte is synced.
-
Key Derivation (
ScryptKdf.kt): A user's password is never used directly as an encryption key. Instead, it runs through Scrypt to derive a strong key-encryption key, making brute-force attacks computationally expensive. -
Master Key Wrapping (
AesKeyWrap.kt&VaultMasterkey.kt): Rather than re-encrypting every file when a password changes, the vault relies on a master key protected via AES Key Wrap. -
Path & Filename Obfuscation (
AesSiv.kt&VaultPathCrypto.kt): Encrypting file contents isn't enough if a file namedtax_returns_2026.pdfis sitting in plaintext on Google Drive. I implemented AES-SIV (Synthetic Initialization Vector) to deterministically encrypt filenames and directory paths while preserving authenticated integrity. -
File Content Encryption (
VaultFileCrypto.kt&VaultEncoding.kt): Actual file payloads are encrypted and encoded into the custom Encrypz vault format before hitting local or cloud storage.
Separating these primitives into distinct, testable modules kept the security boundary clean and made it much easier to audit each step of the encryption pipeline.
Abstracting Storage: Google Drive and Local SAF Vaults
Users shouldn't be locked into a single storage provider. To keep the app flexible, I built an abstraction
layer around EncrypzVaultEngine.kt and VaultRegistry.kt that decouples the
cryptographic operations from where the encrypted bytes actually live.
Right now, the app supports two primary backends:
-
Google Drive (
GoogleDriveVaultBackend.kt&GoogleDriveSyncManager.kt): Handles remote vault synchronization, paired withDriveUploadWorker.ktto offload heavy encrypted uploads to background tasks so the UI stays responsive. For authentication, I implemented a customLoopbackGoogleOAuthServer.ktto manage the OAuth flow cleanly. -
Local Storage (
SafVaultBackend.kt&LocalVaultStorage.kt): Uses Android's Storage Access Framework (SAF) so users can create and manage fully encrypted vaults directly on their device storage or external SD cards without touching the cloud.
Because both backends conform to the same vault engine interface, the rest of the app doesn't need to care whether a file is coming from Google Drive or a local folder.
Balancing Zero-Knowledge Security with Mobile UX
Security tools fail when they are painful to use. If decrypting a photo requires downloading it to the device's public Downloads folder, you've just defeated the purpose of the vault—and ruined the user experience.
To make Encrypz feel like a modern, everyday app, I built the UI in Jetpack Compose with a focus on seamless, in-app media handling:
-
Fast, Secure Access: Typing a strong master password on a phone screen every time you open
the app gets old fast. I implemented biometric authentication (
FingerprintUnlock.kt) alongside a PIN unlock flow (PinUnlockScreen.kt), backed byDeviceSecrets.ktto protect local unlock material. -
In-App Media Viewing: Instead of handing decrypted files off to external apps, I built a
native
PhotosTimeline.kt,PhotoViewer.kt,VaultMediaPlayer.kt, andVaultFilePreviewComponents.kt. Paired with a controlledVaultPreviewCache.kt, users can browse an encrypted photo timeline and stream media directly inside the app without leaking plaintext to the system gallery.
Verifying Cryptographic Integrity with Unit Tests
When you write custom cryptographic plumbing, a silent bug doesn't just crash the app—it can permanently
corrupt a user's files or weaken security. I backed the core engine with a suite of unit tests in
src/test/:
-
VaultCryptoVectorsTest.kt&EncrypzVaultFormatTest.kt: Validate the cryptographic primitives against known test vectors and ensure the vault format remains strictly consistent across reads and writes. -
VaultFileNamesTest.kt: Verifies that filename and path encryption/decryption round-trips cleanly without edge-case collisions. -
GoogleDrivePermissionFlowTest.kt&VaultViewModelTest.kt: Cover the OAuth permission flows and UI state management.
Building Encrypz Android has been a deep dive into the intersection of applied cryptography and mobile systems engineering. Getting the math right is only half the battle; the real challenge is wrapping Scrypt, AES-SIV, and background cloud sync into an interface that feels effortless to use. The project is open-source, and I'm continuing to refine the sync engine, expand media support, and harden the architecture as I push it forward.