Skip to content

SDK Quick Start - Essential Examples

This page provides 6 minimal examples (10-15 lines each) demonstrating core SDK patterns without boilerplate. Each example links to complete production-ready flows with error handling, resource management, and edge cases.

Goal: Get your first SDK call working in under 2 minutes.


// ONE method handles any file size
AuthenticatedSdk sdk = factory.authenticateApplication(clientId, secret);
sdk.encryptFile("my-key", input, output);  // ← Auto-selects compact vs streaming

How it works: The SDK automatically selects compact or streaming format based on input size versus the server-discovered limit (GET /api/v3/crypto/limitsmaxPlaintextBytes, default 4 MB). A compact call that hits the limit falls back to streaming automatically on 413.

Complete production example: Flow 1 - Asymmetric Encrypt/Decrypt


Example 2: Decrypt Any Format (Auto-Detection)

// Works with both compact and streaming formats
sdk.decryptFile(encrypted, decrypted);  // ← Auto-detects input format

How it works: The SDK inspects the ciphertext header to determine if it's a compact JWE token or streaming chunks.

Complete production example: Flow 1 - Asymmetric Encrypt/Decrypt


Example 3: Compact Token for APIs (below the configured limit)

// Single-line JWE for REST API transmission
sdk.encryptFileCompact("api-key", config, output);
String jwe = Files.readString(output);  // ← One-line Base64 token
yourApiClient.post("/your-app/store", jwe);

When to use: Small payloads for microservices, JSON messages, unit tests.

Complete production example: Flow 5 - ML-KEM-512 Compact


Example 4: Large File Streaming (Constant Memory)

// 500 GB file, 64 KB RAM
sdk.encryptFileStream("archive-key", largeFile, output);

When to use: GB-scale backups, log archives, media files.

Complete production example: Flow 1 - ML-KEM-512 Streaming Encrypt/Decrypt


Example 5: Quantum-Resistant Encryption

// A composite hybrid key (classical + PQC) is provisioned in the control plane;
// the data-plane call is identical to any other key.
sdk.encryptFile("hybrid-key", secret, encrypted);

When to use: Regulatory compliance (NIST CSWP 39, GSA PQC, EU/BSI/ANSSI standards).

Complete production example: Flow 18 - Composite Hybrid Keys


Example 6: Migrate RSA to Post-Quantum

// Zero-exposure migration (never touches plaintext)
sdk.reencryptFile("old-rsa-key", "new-mlkem-key", oldCiphertext, newCiphertext);

When to use: Upgrade legacy RSA/EC ciphertexts to ML-KEM without decrypting.

Complete production example: Flow 4 - Asymmetric Re-encrypt


Next Steps


Pattern Quick Reference

Pattern Method Use Case Example Flow
🔄 Auto-Detection encryptFile(), decryptFile() Any file size (recommended) Flow 1
📦 Force Compact encryptFileCompact() Below the configured limit (API tokens) Flow 5
🌊 Force Streaming encryptFileStream() Large files (GB-scale) Flow 1
🔐 Sign + Encrypt Nested operations Authenticated encryption Flow 17
🔄 Re-encrypt reencryptFile() Migrate ciphertexts Flow 4
🏗️ Composite Keys COMPOSITE_KEM_COMBINE Quantum-resistant Flow 18

Tip: Start with auto-detection methods (encryptFile, decryptFile) for 90% of use cases. Only use explicit format methods when you have specific requirements.