Plugin.Maui.FileVault 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Plugin.Maui.FileVault --version 1.0.1
                    
NuGet\Install-Package Plugin.Maui.FileVault -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Plugin.Maui.FileVault" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Plugin.Maui.FileVault" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Plugin.Maui.FileVault" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Plugin.Maui.FileVault --version 1.0.1
                    
#r "nuget: Plugin.Maui.FileVault, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Plugin.Maui.FileVault@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Plugin.Maui.FileVault&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Plugin.Maui.FileVault&version=1.0.1
                    
Install as a Cake Tool

Plugin.Maui.FileVault

Secure local files for .NET MAUI on iOS and Android.

The package stores app-private files as AES-256-GCM ciphertext, keeps the master key in the platform secure store, and manages the file lifecycle (expire, purge, lock, destroy).

Feature What it does
Encryption AES-256-GCM per file, unique nonce, authenticated decrypt
Key protection Master key in iOS Keychain / Android Keystore via SecureStorage
Passphrase Optional PBKDF2-SHA256 wrap so the key never sits in SecureStorage
Platform files iOS NSFileProtectionComplete + backup exclusion; Android app-private / no-backup dir
Lifecycle TTL, idle timeout, purge on resume, lock on background, secure delete, quota eviction

Install

dotnet add package Plugin.Maui.FileVault

Quick start

using Plugin.Maui.FileVault;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .UseFileVault(options =>
            {
                options.DefaultTimeToLive = TimeSpan.FromDays(30);
                options.LockOnBackground = true;
                options.ExcludeFromBackup = true;
            });

        return builder.Build();
    }
}

Resolve IFileVault or use FileVault.Current:

var vault = handler.Services.GetRequiredService<IFileVault>();

await vault.WriteTextAsync("notes/pin.txt", "1234", new VaultWriteOptions
{
    TimeToLive = TimeSpan.FromHours(12),
    Metadata = new Dictionary<string, string> { ["kind"] = "pin" }
});

var pin = await vault.ReadTextAsync("notes/pin.txt");
var files = await vault.ListAsync("notes");

Device-key vaults unlock automatically on first use. Passphrase vaults stay locked until UnlockAsync.

Passphrase lock

builder.UseFileVault(options => options.RequirePassphrase = true);

await vault.UnlockAsync(passphrase);
await vault.LockAsync();
await vault.ChangePassphraseAsync(current, next);

ChangePassphraseAsync(current, newPassphrase: null) moves the master key back to SecureStorage. Files are not re-encrypted; only the key wrap changes.

Expiration and purge

options.DefaultTimeToLive = TimeSpan.FromDays(7);
options.MaxIdleTime = TimeSpan.FromHours(6);
options.AutoPurgeOnResume = true;

await vault.SetExpirationAsync("cache/token.json", DateTimeOffset.UtcNow.AddMinutes(15));
var removed = await vault.PurgeExpiredAsync();

Reading an expired file deletes it and throws FileVaultException with FileVaultError.Expired.

Quota

options.MaxVaultSizeBytes = 10 * 1024 * 1024;
options.EvictionPolicy = VaultEvictionPolicy.LeastRecentlyUsed;

await vault.WriteAsync("photo.jpg", bytes, new VaultWriteOptions { Pin = true });

Pinned files are skipped during eviction. VaultEvictionPolicy.None fails the write with QuotaExceeded.

Lifecycle hooks

UseFileVault wires platform resume/pause:

  • Resume — purge expired and idle files
  • Background — lock the vault when LockOnBackground is true
vault.NotifyForeground();
vault.NotifyBackground();

DestroyAsync securely deletes every vault file, the manifest, and the stored key.

Without the generic host

var vault = FileVault.Create(new FileVaultOptions
{
    DefaultTimeToLive = TimeSpan.FromDays(1)
});

await vault.UnlockAsync();

Target frameworks

The package targets net10.0, net10.0-android, and net10.0-ios.

Pack from source

dotnet pack src/Plugin.Maui.FileVault/Plugin.Maui.FileVault.csproj -c Release -o artifacts

The .nupkg is written to artifacts/Plugin.Maui.FileVault.1.0.0.nupkg.

License

MIT

Support

If this plugin saved you a weekend of native plumbing, consider buying me a coffee. Your support keeps it maintained, documented, and free.

Buy Me A Coffee

This library stays open source. A coffee helps cover time for bug fixes, new features, and docs.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-android36.0 is compatible.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-ios26.0 is compatible.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net10.0-android36.0

    • No dependencies.
  • net10.0-ios26.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.8 77 9/2/2026
1.0.7 91 8/30/2026
1.0.6 81 8/30/2026
1.0.5 96 8/29/2026
1.0.4 91 8/28/2026
1.0.3 92 8/28/2026
1.0.2 90 8/28/2026
1.0.1 95 8/28/2026
1.0.0 92 8/27/2026

Include the Buy Me a Coffee support section in the package README.