# sreejithes/encrypto architecture

> Architecture diagram of the GitHub repository sreejithes/encrypto, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sreejithes/encrypto
- Repository: https://github.com/sreejithes/encrypto

## Overview

#### Purpose and Public Entry Point
Encrypto is a Dart/Flutter security package exposing unified APIs for cryptography, password protection, JWTs, encoding, randomness, and platform-backed secret storage. Consumers import `lib/encrypto.dart`, which acts as the package façade and composes the feature modules under `lib/`.

#### API Facade and Service Boundaries
The public `Encrypto` surface delegates operations to focused domains rather than exposing platform code directly. This separates application-facing APIs from crypto implementations and storage adapters.
- `lib/encrypto.dart`
- `lib/encryption/encryption.dart`
- `lib/storage/secure_storage.dart`

#### Symmetric Encryption Pipeline
Encryption accepts plaintext and caller-supplied key material, produces an `EncryptionResult`, and supports AES variants and ChaCha20. Decryption consumes that result and compatible key material. AES-GCM is the intended default; AES-CBC is retained for compatibility.
- `lib/encryption/aes.dart`
- `lib/encryption/chacha20.dart`
- `lib/encryption/encryption_result.dart`

#### Asymmetric Cryptography
Separate implementations cover signing, key agreement, and RSA encryption/signature use cases. These form a distinct boundary from symmetric encryption because their key types, protocols, and failure modes differ.
- `lib/asymmetric/asymmetric.dart`
- `lib/asymmetric/ed25519.dart`
- `lib/asymmetric/x25519.dart`
- `lib/asymmetric/rsa.dart`

#### Integrity, Derivation, and Password Security
Hashing and HMAC provide integrity primitives; KDF implementations derive keys or password hashes. Password security is a higher-level workflow built around Argon2id hashing and verification, rather than requiring callers to manage raw KDF details.
- `lib/hashing/hashing.dart`
- `lib/hmac/hmac.dart`
- `lib/kdf/argon2.dart`
- `lib/kdf/pbkdf2.dart`
- `lib/password/password_security.dart`

#### Token, Encoding, and Security Utilities
JWT creation/verification uses the package’s crypto capabilities at the token boundary. Encoding converts binary crypto artifacts to transport/storage forms, while security utilities provide cryptographically secure randomness and constant-time equality for sensitive comparisons.
- `lib/jwt/jwt.dart`
- `lib/encoding/encoding.dart`
- `lib/security/secure_random.dart`
- `lib/security/constant_time.dart`

#### Platform Runtime and Persistent Secrets
The core library runs in Dart/Flutter. Secure persistence is delegated to native platform facilities—Android Keystore and iOS Keychain—through the storage abstraction, keeping secret-at-rest behavior outside general crypto APIs. The included example is a multi-platform Flutter host demonstrating package integration.
- `lib/storage/secure_storage.dart`
- `example/lib/main.dart`
- `example/android/app/src/main/kotlin/com/example/encrypto_example/MainActivity.kt`
- `example/ios/Runner/AppDelegate.swift`

Main entry points: [`lib/encrypto.dart`](https://github.com/sreejithes/encrypto/blob/main/lib/encrypto.dart) (Encrypto facade), [`lib/asymmetric/asymmetric.dart`](https://github.com/sreejithes/encrypto/blob/main/lib/asymmetric/asymmetric.dart) (Asymmetric API), [`lib/encryption/encryption.dart`](https://github.com/sreejithes/encrypto/blob/main/lib/encryption/encryption.dart) (Encryption API), [`example/lib/main.dart`](https://github.com/sreejithes/encrypto/blob/main/example/lib/main.dart) (Flutter example)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public API"]
  node_facade["Encrypto facade<br/>package API<br/>[encrypto.dart]"]
end

subgraph group_crypto["Cryptography"]
  node_encryption["Encryption API<br/>symmetric service<br/>[encryption.dart]"]
  node_aes["AES<br/>cipher implementation<br/>[aes.dart]"]
  node_chacha["ChaCha20<br/>cipher implementation<br/>[chacha20.dart]"]
  node_encryption_result["Encryption result<br/>ciphertext value"]
  node_asymmetric["Asymmetric API<br/>asymmetric service<br/>[asymmetric.dart]"]
  node_ed25519["Ed25519<br/>signing implementation<br/>[ed25519.dart]"]
  node_x25519["X25519<br/>key agreement implementation<br/>[x25519.dart]"]
  node_rsa["RSA<br/>encryption and signature<br/>[rsa.dart]"]
end

subgraph group_security["Security Services"]
  node_hashing["Hashing<br/>integrity primitives<br/>[hashing.dart]"]
  node_hmac["HMAC<br/>integrity primitive<br/>[hmac.dart]"]
  node_argon2["Argon2id<br/>KDF<br/>[argon2.dart]"]
  node_pbkdf2["PBKDF2<br/>[pbkdf2.dart]"]
  node_password["Password security<br/>password workflow"]
  node_jwt["JWT<br/>token service<br/>[jwt.dart]"]
  node_encoding["Encoding<br/>binary codec<br/>[encoding.dart]"]
  node_secure_random["Secure random<br/>randomness utility<br/>[secure_random.dart]"]
  node_constant_time["Constant-time equality<br/>comparison utility<br/>[constant_time.dart]"]
end

subgraph group_platform["Platform Storage"]
  node_secure_storage["Secure storage<br/>storage abstraction"]
  node_android[("Android Keystore<br/>native secret store<br/>[MainActivity.kt]")]
  node_ios[("iOS Keychain<br/>native secret store<br/>[AppDelegate.swift]")]
end

subgraph group_example["Example Host"]
  node_example_app["Flutter example<br/>integration host<br/>[main.dart]"]
end

node_facade -->|"exposes"| node_encryption
node_facade -->|"exposes"| node_asymmetric
node_facade -->|"exposes"| node_password
node_facade -->|"exposes"| node_jwt
node_facade -->|"exposes"| node_encoding
node_facade -->|"exposes"| node_secure_random
node_facade -->|"exposes"| node_constant_time
node_facade -->|"exposes"| node_secure_storage
node_encryption -->|"selects cipher"| node_aes
node_encryption -->|"selects cipher"| node_chacha
node_encryption -->|"produces and consumes"| node_encryption_result
node_asymmetric -->|"signing"| node_ed25519
node_asymmetric -->|"key agreement"| node_x25519
node_asymmetric -->|"encryption and signatures"| node_rsa
node_password -->|"hashes and verifies with"| node_argon2
node_jwt -.->|"uses signing capabilities"| node_asymmetric
node_jwt -.->|"uses MAC capabilities"| node_hmac
node_hmac -->|"builds on hashes"| node_hashing
node_secure_storage -->|"uses on Android"| node_android
node_secure_storage -->|"uses on iOS"| node_ios
node_example_app -->|"integrates"| node_facade
node_example_app -.->|"host runtime"| node_android
node_example_app -.->|"host runtime"| node_ios

click node_facade "https://github.com/sreejithes/encrypto/blob/main/lib/encrypto.dart"
click node_encryption "https://github.com/sreejithes/encrypto/blob/main/lib/encryption/encryption.dart"
click node_aes "https://github.com/sreejithes/encrypto/blob/main/lib/encryption/aes.dart"
click node_chacha "https://github.com/sreejithes/encrypto/blob/main/lib/encryption/chacha20.dart"
click node_encryption_result "https://github.com/sreejithes/encrypto/blob/main/lib/encryption/encryption_result.dart"
click node_asymmetric "https://github.com/sreejithes/encrypto/blob/main/lib/asymmetric/asymmetric.dart"
click node_ed25519 "https://github.com/sreejithes/encrypto/blob/main/lib/asymmetric/ed25519.dart"
click node_x25519 "https://github.com/sreejithes/encrypto/blob/main/lib/asymmetric/x25519.dart"
click node_rsa "https://github.com/sreejithes/encrypto/blob/main/lib/asymmetric/rsa.dart"
click node_hashing "https://github.com/sreejithes/encrypto/blob/main/lib/hashing/hashing.dart"
click node_hmac "https://github.com/sreejithes/encrypto/blob/main/lib/hmac/hmac.dart"
click node_argon2 "https://github.com/sreejithes/encrypto/blob/main/lib/kdf/argon2.dart"
click node_pbkdf2 "https://github.com/sreejithes/encrypto/blob/main/lib/kdf/pbkdf2.dart"
click node_password "https://github.com/sreejithes/encrypto/blob/main/lib/password/password_security.dart"
click node_jwt "https://github.com/sreejithes/encrypto/blob/main/lib/jwt/jwt.dart"
click node_encoding "https://github.com/sreejithes/encrypto/blob/main/lib/encoding/encoding.dart"
click node_secure_random "https://github.com/sreejithes/encrypto/blob/main/lib/security/secure_random.dart"
click node_constant_time "https://github.com/sreejithes/encrypto/blob/main/lib/security/constant_time.dart"
click node_secure_storage "https://github.com/sreejithes/encrypto/blob/main/lib/storage/secure_storage.dart"
click node_android "https://github.com/sreejithes/encrypto/blob/main/example/android/app/src/main/kotlin/com/example/encrypto_example/MainActivity.kt"
click node_ios "https://github.com/sreejithes/encrypto/blob/main/example/ios/Runner/AppDelegate.swift"
click node_example_app "https://github.com/sreejithes/encrypto/blob/main/example/lib/main.dart"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_facade toneBlue
class node_encryption,node_aes,node_chacha,node_encryption_result,node_asymmetric,node_ed25519,node_x25519,node_rsa toneAmber
class node_hashing,node_hmac,node_argon2,node_pbkdf2,node_password,node_jwt,node_encoding,node_secure_random,node_constant_time toneMint
class node_secure_storage,node_android,node_ios toneRose
class node_example_app toneIndigo
```

## Components

### Public API

- [Encrypto facade](https://github.com/sreejithes/encrypto/blob/main/lib/encrypto.dart): package API · Unified consumer entry point. · `lib/encrypto.dart`

### Cryptography

- [Encryption API](https://github.com/sreejithes/encrypto/blob/main/lib/encryption/encryption.dart): symmetric service · `lib/encryption/encryption.dart`
- [AES](https://github.com/sreejithes/encrypto/blob/main/lib/encryption/aes.dart): cipher implementation · AES-GCM is the default; CBC remains for compatibility. · `lib/encryption/aes.dart`
- [ChaCha20](https://github.com/sreejithes/encrypto/blob/main/lib/encryption/chacha20.dart): cipher implementation · `lib/encryption/chacha20.dart`
- [Encryption result](https://github.com/sreejithes/encrypto/blob/main/lib/encryption/encryption_result.dart): ciphertext value · Carries output consumed during decryption. · `lib/encryption/encryption_result.dart`
- [Asymmetric API](https://github.com/sreejithes/encrypto/blob/main/lib/asymmetric/asymmetric.dart): asymmetric service · `lib/asymmetric/asymmetric.dart`
- [Ed25519](https://github.com/sreejithes/encrypto/blob/main/lib/asymmetric/ed25519.dart): signing implementation · `lib/asymmetric/ed25519.dart`
- [X25519](https://github.com/sreejithes/encrypto/blob/main/lib/asymmetric/x25519.dart): key agreement implementation · `lib/asymmetric/x25519.dart`
- [RSA](https://github.com/sreejithes/encrypto/blob/main/lib/asymmetric/rsa.dart): encryption and signature · `lib/asymmetric/rsa.dart`

### Security Services

- [Hashing](https://github.com/sreejithes/encrypto/blob/main/lib/hashing/hashing.dart): integrity primitives · `lib/hashing/hashing.dart`
- [HMAC](https://github.com/sreejithes/encrypto/blob/main/lib/hmac/hmac.dart): integrity primitive · `lib/hmac/hmac.dart`
- [Argon2id](https://github.com/sreejithes/encrypto/blob/main/lib/kdf/argon2.dart): KDF · `lib/kdf/argon2.dart`
- [PBKDF2](https://github.com/sreejithes/encrypto/blob/main/lib/kdf/pbkdf2.dart): KDF · `lib/kdf/pbkdf2.dart`
- [Password security](https://github.com/sreejithes/encrypto/blob/main/lib/password/password_security.dart): password workflow · High-level Argon2id hash and verification. · `lib/password/password_security.dart`
- [JWT](https://github.com/sreejithes/encrypto/blob/main/lib/jwt/jwt.dart): token service · Creates and verifies signed tokens. · `lib/jwt/jwt.dart`
- [Encoding](https://github.com/sreejithes/encrypto/blob/main/lib/encoding/encoding.dart): binary codec · `lib/encoding/encoding.dart`
- [Secure random](https://github.com/sreejithes/encrypto/blob/main/lib/security/secure_random.dart): randomness utility · `lib/security/secure_random.dart`
- [Constant-time equality](https://github.com/sreejithes/encrypto/blob/main/lib/security/constant_time.dart): comparison utility · `lib/security/constant_time.dart`

### Platform Storage

- [Secure storage](https://github.com/sreejithes/encrypto/blob/main/lib/storage/secure_storage.dart): storage abstraction · Delegates secrets at rest to native facilities. · `lib/storage/secure_storage.dart`
- [Android Keystore](https://github.com/sreejithes/encrypto/blob/main/example/android/app/src/main/kotlin/com/example/encrypto_example/MainActivity.kt): native secret store · `example/android/app/src/main/kotlin/com/example/encrypto_example/MainActivity.kt`
- [iOS Keychain](https://github.com/sreejithes/encrypto/blob/main/example/ios/Runner/AppDelegate.swift): native secret store · `example/ios/Runner/AppDelegate.swift`

### Example Host

- [Flutter example](https://github.com/sreejithes/encrypto/blob/main/example/lib/main.dart): integration host · Multi-platform package integration example. · `example/lib/main.dart`

## Connections

- Encrypto facade → Encryption API: exposes
- Encrypto facade → Asymmetric API: exposes
- Encrypto facade → Password security: exposes
- Encrypto facade → JWT: exposes
- Encrypto facade → Encoding: exposes
- Encrypto facade → Secure random: exposes
- Encrypto facade → Constant-time equality: exposes
- Encrypto facade → Secure storage: exposes
- Encryption API → AES: selects cipher
- Encryption API → ChaCha20: selects cipher
- Encryption API → Encryption result: produces and consumes
- Asymmetric API → Ed25519: signing
- Asymmetric API → X25519: key agreement
- Asymmetric API → RSA: encryption and signatures
- Password security → Argon2id: hashes and verifies with
- JWT → Asymmetric API: uses signing capabilities
- JWT → HMAC: uses MAC capabilities
- HMAC → Hashing: builds on hashes
- Secure storage → Android Keystore: uses on Android
- Secure storage → iOS Keychain: uses on iOS
- Flutter example → Encrypto facade: integrates
- Flutter example → Android Keystore: host runtime
- Flutter example → iOS Keychain: host runtime
