https://github.com/garvinschaub/smallbin
SmallBin is a lightweight, secure file storage library for .NET that enables storing multiple files in a single encrypted container with metadata support
https://github.com/garvinschaub/smallbin
cryptography csharp database developer-tool developer-tools dotnet encryption file-management file-management-system file-manager file-storage library nuget nuget-package secure-storage security utilities utility-library wpf
Last synced: 18 days ago
JSON representation
SmallBin is a lightweight, secure file storage library for .NET that enables storing multiple files in a single encrypted container with metadata support
- Host: GitHub
- URL: https://github.com/garvinschaub/smallbin
- Owner: GarvinSchaub
- License: mit
- Created: 2024-11-18T13:55:58.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2025-02-27T13:00:11.000Z (3 months ago)
- Last Synced: 2025-05-05T22:55:48.129Z (18 days ago)
- Topics: cryptography, csharp, database, developer-tool, developer-tools, dotnet, encryption, file-management, file-management-system, file-manager, file-storage, library, nuget, nuget-package, secure-storage, security, utilities, utility-library, wpf
- Language: C#
- Homepage: https://www.nuget.org/packages/SmallBin
- Size: 188 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SmallBin
[](https://www.nuget.org/packages/SmallBin/)
[](https://opensource.org/licenses/MIT)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.
## 🔑 Key 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
```shell
dotnet add package SmallBin
```## 🚀 Quick Start
### Creating a New Database
```csharp
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();// The builder pattern makes it clear which options are being configured
// and allows for future extensibility without breaking changes
```### Adding Files
```csharp
// Add a single file with tags
db.SaveFile("document.pdf",
tags: new List { "work", "reports" },
contentType: "application/pdf");// Add multiple files
foreach (string file in Directory.GetFiles("source", "*.jpg"))
{
db.SaveFile(file,
tags: new List { "photos" },
contentType: "image/jpeg");
}
```### Retrieving Files
```csharp
// Get file by ID
byte[] fileContent = db.GetFile(fileId);
File.WriteAllBytes("exported.pdf", fileContent);
```### Searching Files
```csharp
// 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 { "photos" }
});
```### Managing Metadata
```csharp
db.UpdateMetadata(fileId, entry =>
{
entry.Tags.Add("important");
entry.CustomMetadata["author"] = "John Doe";
entry.ContentType = "application/pdf";
});
```### Deleting Files
```csharp
db.DeleteFile(fileId);
```### Configuring Logging
```csharp
// 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();
```### Configuring Logging
```csharp
// 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
```csharp
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## 📄 License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## 👥 Contributing
Contributions welcome! NEVER submit pull requests directly to the main branch.
## Version Impact
| Type | Version Change | When to Use |
|------|---------------|-------------|
| `breaking:` | MAJOR (1.0.0) | Incompatible API changes, removing features |
| `major:` | MAJOR (1.0.0) | Same as breaking |
| `feat:` | MINOR (0.1.0) | New features, capabilities, or enhancements |
| `fix:` | PATCH (0.0.1) | Bug fixes, correcting behavior |
| `refactor:` | PATCH | Code restructuring without behavior change |
| `chore:` | PATCH | Build process, dependencies, tooling |
| `style:` | PATCH | Code formatting, naming (no logic change) |
| `test:` | PATCH | Adding/modifying tests |
| `docs:` | NONE | Documentation only |
| `ci:` | NONE | CI/CD changes |## Examples
```
breaking: remove support for XML config files
feat: add dark mode theme support
fix: prevent crash when user input is empty
chore: update NuGet packages
refactor: simplify login logic
style: fix code indentation
test: add unit tests for auth service
docs: update API documentation
ci: add new deploy stage
```## Additional Tips
- Use present tense ("add feature" not "added feature")
- Keep first line under 70 characters
- Add scope for clarity: `feat(auth):`, `fix(db):`
- Include ticket number if needed: `feat: add login (#123)`## ⭐ Show Your Support
If you find this project useful, please consider giving it a star on GitHub!