SmallBin 2.0.0

dotnet add package SmallBin --version 2.0.0
                    
NuGet\Install-Package SmallBin -Version 2.0.0
                    
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="SmallBin" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SmallBin" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SmallBin" />
                    
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 SmallBin --version 2.0.0
                    
#r "nuget: SmallBin, 2.0.0"
                    
#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 SmallBin@2.0.0
                    
#: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=SmallBin&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SmallBin&version=2.0.0
                    
Install as a Cake Tool

SmallBin

SmallBin is a lightweight, secure file storage library for .NET that enables storing multiple files in a single encrypted container with metadata support and comprehensive logging capabilities.

Features

  • Single-file encrypted database
  • Password-based encryption (AES-256)
  • File metadata and tagging
  • File compression support
  • Search functionality
  • Thread-safe operations
  • Flexible logging system with console and file output
  • Extensible logging interface

Installation

dotnet add package SmallBin

Usage

Creating a New Database

using SmallBin;
using SmallBin.Logging;

// Optional: Configure logging
var logger = new ConsoleLogger(); // or new FileLogger("app.log")

// Create or open an encrypted database using the builder pattern
using var db = SecureFileDatabase.Create("mydata.sdb", "password123")
    .WithoutCompression()  // Optional: disable compression (enabled by default)
    .WithAutoSave()       // Optional: enable auto-save (disabled by default)
    .WithLogger(logger)   // Optional: add logging support
    .Build();

Adding Files

// Add a single file with tags
db.SaveFile("document.pdf",
    tags: new List<string> { "work", "reports" },
    contentType: "application/pdf");

// Add multiple files
foreach (string file in Directory.GetFiles("source", "*.jpg"))
{
    db.SaveFile(file,
        tags: new List<string> { "photos" },
        contentType: "image/jpeg");
}

Retrieving Files

// Get file by ID
byte[] fileContent = db.GetFile(fileId);
File.WriteAllBytes("exported.pdf", fileContent);

Searching Files

// Search by filename
var criteria = new SearchCriteria { FileName = "report" };
var files = db.Search(criteria);

// Search by tags
var photoFiles = db.Search(new SearchCriteria 
{ 
    Tags = new List<string> { "photos" } 
});

// Advanced search with multiple criteria
var searchCriteria = new SearchCriteria
{
    FileName = "report",
    Tags = new List<string> { "important" },
    StartDate = DateTime.Now.AddDays(-7),
    EndDate = DateTime.Now,
    ContentType = "application/pdf",
    CustomMetadata = new Dictionary<string, string>
    {
        { "author", "John Doe" }
    }
};
var results = db.Search(searchCriteria);

Managing Metadata

db.UpdateMetadata(fileId, entry => 
{
    entry.Tags.Add("important");
    entry.CustomMetadata["author"] = "John Doe";
    entry.ContentType = "application/pdf";
});

Deleting Files

db.DeleteFile(fileId);

Configuring Logging

// Console logging
var consoleLogger = new ConsoleLogger();

// File logging
var fileLogger = new FileLogger("app.log");

// Custom logging by implementing ILogger
public class CustomLogger : ILogger
{
    public void Log(string message)
    {
        // Custom logging implementation
    }
}

// Using multiple loggers
var db = SecureFileDatabase.Create("mydata.sdb", "password123")
    .WithLogger(consoleLogger)
    .WithLogger(fileLogger)
    .Build();

WPF Application Example

public partial class MainWindow : Window
{
    private SecureFileDatabase _db;
    private ILogger _logger;

    private void OpenDatabase()
    {
        _logger = new FileLogger("app.log");
        _db = SecureFileDatabase.Create("data.sdb", "password123")
            .WithAutoSave() // Enable auto-save for WPF applications
            .WithLogger(_logger)
            .Build();
    }

    private void AddFile_Click(object sender, RoutedEventArgs e)
    {
        var dialog = new OpenFileDialog { Multiselect = true };
        if (dialog.ShowDialog() == true)
        {
            foreach (string filename in dialog.FileNames)
            {
                _db.SaveFile(filename);
            }
        }
    }
}

Security Considerations

  • Passwords should be strong and securely stored
  • Database files contain encrypted content
  • Each file has its own encryption IV
  • Uses PBKDF2 for key derivation
  • All operations are logged for security auditing
  • AES-256 encryption for maximum security
  • Thread-safe operations for concurrent access

License

MIT License

Contributing

Contributions welcome! NEVER submit pull requests directly to the main branch.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.