Skip to content

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FastKeychain 0.1.0 β€” Hardware-Backed Windows Credential Manager & DPAPI Key Management for Java

Status License: MIT Java Platform JitPack


⚑ Hardware-bound encryption via Windows DPAPI & persistent credentials in the Windows Credential Vault with zero-heap memory scrubbing.

FastKeychain eliminates the widespread practice of storing sensitive API tokens, application licenses, and passphrases in insecure plaintext files or raw configuration keys. It binds encrypted secrets directly to the current Windows user profile and the machine's hardware TPM 2.0 security chip, while scrubbing memory buffers immediately after use to prevent RAM dump inspection.


Quick Start

import fastkeychain.FastKeychain;

public class Example {
    public static void main(String[] args) {
        // Transparent Windows DPAPI (CryptProtectData / CryptUnprotectData)
        String sensitiveToken = "sk-ant-api03-live-99882244-SECRET";
        byte[] encrypted = FastKeychain.protectString(sensitiveToken);
        String decrypted = FastKeychain.unprotectString(encrypted);

        // Persistent Windows Credential Manager (CredWriteW / CredReadW)
        FastKeychain.writeSecret("MyApp/License", "FSC-PRO-KEY-2026".getBytes());
        byte[] licenseBytes = FastKeychain.readSecret("MyApp/License");
        FastKeychain.deleteSecret("MyApp/License");

        // Zero-allocation memory wiping
        FastKeychain.wipe(licenseBytes);
    }
}

Table of Contents


Why FastKeychain?

Standard Java applications suffer from fundamental security vulnerabilities when handling credentials:

  1. Plaintext Leaks on Disk: Developers persist API keys or licenses in .json, .properties, or .env files readable by any process or malware.
  2. RAM Dump Vulnerability: Standard java.lang.String instances are immutable and remain cached in the JVM garbage collector heap indefinitely.
  3. No Hardware Binding: Encrypted files can simply be copied to other machines without restriction.

FastKeychain solves this:

  • TPM 2.0 & OS User Binding: Uses CryptProtectData (DPAPI) β€” data can only be decrypted on the exact same hardware by the same logged-in Windows user.
  • Windows Credential Manager Integration: Native persistence via CredWriteW / CredReadW residing in the secure Windows Credential Vault.
  • Zero-String Memory Scrubbing: Automatically scrubs native buffers with SecureZeroMemory and primitive Java arrays with Arrays.fill((byte)0).

Key Features

  • πŸ›‘οΈ Windows DPAPI Direct Access β€” Hardware-tied CryptProtectData and CryptUnprotectData in sub-millisecond execution.
  • πŸ—„οΈ Windows Vault Integration β€” Read, write, and delete credentials directly in the Windows Credential Manager.
  • 🧹 Zero-Leak Memory Scrubbing β€” Immediate memory zeroization (FastKeychain.wipe) preventing RAM forensics and heap dumps.
  • ⚑ Zero-Copy Native Bridge β€” High-speed JNI bridge with zero external DLL dependencies (links directly to Crypt32.lib & Advapi32.lib).
  • πŸ”— FastJava Ecosystem Synergy β€” Seamlessly integrates with FastCore, FastCrypto, and FastScreenCaptureApp.

Real-World Use Cases

  • πŸ”‘ AI Agent & LLM API Keys (FastAgent): Store Anthropic, OpenAI, or Google API keys safely in the Windows Vault without saving them in .env or project source code.
  • πŸ’Ό Commercial Software License Validation: Protect and verify offline license tokens (FSC-PRO-...) with hardware TPM anchoring so they cannot be copied to another machine.
  • πŸ” Master Key Storage for FastCrypto: Securely store 256-bit AES master keys and auto-unlock them at runtime without prompting the user for passwords on every start.
  • 🌐 Enterprise Cloud / DB Credentials: Retrieve database connection passwords and service credentials on-demand and wipe them from RAM immediately after socket connection.

Architecture & Security Pipeline

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Java Application Layer                   β”‚
β”‚                     (FastKeychain.java)                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚ JNI Bridge (< 1 Β΅s)
                               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                fastkeychain.dll (MSVC x64)                  β”‚
β”‚       β”œβ”€β”€ CryptProtectDataW / CryptUnprotectDataW           β”‚
β”‚       β”œβ”€β”€ CredWriteW / CredReadW / CredDeleteW              β”‚
β”‚       └── SecureZeroMemory() Buffers                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚ Hardware-Backed Storage
                               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         Windows Security Subsystem & TPM 2.0 Chip           β”‚
β”‚           (DPAPI Master Keys & Credential Vault)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Performance Benchmarks

Real Test Execution Results

Empirical latency and throughput benchmarks measured on Windows 11 with hardware TPM 2.0 and Windows Credential Manager integration (run-benchmark.bat):

Operation / Benchmark Java Standard (.env / File / KeyStore) FastKeychain Hardware Native Security & Performance Advantage
DPAPI Hardware Protect N/A (Plaintext file / Java KeyStore) 174.00 Β΅s (~5,750 ops/s) Hardware TPM 2.0 + User DPAPI sealed
DPAPI Hardware Unprotect N/A (Plaintext in JVM heap) 144.54 Β΅s (~6,920 ops/s) Instant unseal; 0 offline disk extraction
Windows Vault Write + Read ~15–40 ms (Disk file I/O + JSON parsing) 5.75 ms (~175 cycles/s) Persistent, encrypted OS Credential Vault
Memory Sanitization Non-scrubbed (String immutable in GC) < 0.05 Β΅s (SecureZeroMemory) 100% RAM Forensics & Heap Dump Immunity

Note

Environment & Setup: Measured on a Microsoft Surface Pro 8 (11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz, 4C/8T), Windows 11 Home (x64), OpenJDK 21 LTS with hardware TPM 2.0 chip and Windows Hello security subsystem. Standard Java stores strings in GC heap memory where they persist indefinitely; FastKeychain integrates with bare-metal Windows kernel DPAPI and zeroizes native memory immediately upon cryptographic consumption.


API Quick Reference

Method Return Type Description
protectData(byte[] data, byte[] entropy) byte[] Encrypts raw byte array via Windows DPAPI
unprotectData(byte[] data, byte[] entropy) byte[] Decrypts DPAPI ciphertext byte array
protectString(String secret) byte[] Convenience method: Encrypts UTF-8 string with DPAPI
unprotectString(byte[] ciphertext) String Convenience method: Decrypts DPAPI ciphertext to String
writeSecret(String target, byte[] secret) boolean Persists generic credential into Windows Vault
readSecret(String target) byte[] Reads generic credential from Windows Vault
deleteSecret(String target) boolean Removes credential from Windows Vault
wipe(byte[] secret) void Overwrites memory buffer with 0x00 via SecureZeroMemory

Installation

FastKeychain is distributed via JitPack. It requires FastCore as the unified native library loader.

Option 1: Maven (pom.xml)

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependencies>
    <!-- FastKeychain Core -->
    <dependency>
        <groupId>com.github.andrestubbe</groupId>
        <artifactId>FastKeychain</artifactId>
        <version>0.1.0</version>
    </dependency>

    <!-- FastCore Native Loader -->
    <dependency>
        <groupId>com.github.andrestubbe</groupId>
        <artifactId>FastCore</artifactId>
        <version>0.1.0</version>
    </dependency>
</dependencies>

Option 2: Gradle (build.gradle)

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.andrestubbe:FastKeychain:0.1.0'
    implementation 'com.github.andrestubbe:FastCore:0.1.0'
}

Option 3: Direct Download (No Build Tool)

Download the latest pre-compiled JARs:

  1. πŸ“¦ FastKeychain-0.1.0.jar
  2. βš™οΈ FastCore-0.1.0.jar

Technical Examples & Hero Demos

Example / Demo Description Path Run Command
Interactive Showcase Demo Complete round-trip lifecycle demo showcasing DPAPI token sealing, Credential Vault persistence, and RAM scrubbing. examples/Demo/Demo.java run-demo.bat
Microsecond Benchmarks High-precision performance suite measuring hardware encryption latency and ops/sec. examples/Benchmark/Benchmark.java run-benchmark.bat

Documentation

  • REFERENCE.md: Full API descriptions and security contracts.
  • PHILOSOPHY.md: The engineering rationale for hardware-anchored zero-heap security.
  • ROADMAP.md: Future milestones (DPAPI-NG, macOS Keychain, Linux Secret Service).
  • CHANGELOG.md: Detailed version history.

Platform Support

Platform Hardware Security Status
Windows 10 / 11 (x64) TPM 2.0 / DPAPI / Credential Vault βœ… Fully Supported
Windows Server 2016+ (x64) TPM / DPAPI / Credential Vault βœ… Fully Supported
macOS / Linux Under Development (v0.5.0) 🚧 Planned

Related Projects

  • FastCrypto β€” Hardware-accelerated AES-GCM & SIMD cryptography
  • FastCore β€” Native library loader with local fallback
  • FastScreen β€” DirectX DXGI screen capture engine
  • FastTheme β€” Windows native window styling & DWM theme engine

License

MIT License β€” See LICENSE for details.


Part of the FastJava Ecosystem β€” Making the JVM faster. ⚑

About

πŸ” Hardware-backed Windows Credential Manager and DPAPI key management for Java

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages