Thuro.Utility 1.2.1

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

Thuro.Utility

A comprehensive utility library for .NET Standard 2.0 providing common helper methods and services for Azure integration, encryption, caching, and more.

Features

  • Azure Blob Storage Service - Upload, download, delete, and manage files in Azure Blob Storage
  • Azure Key Vault Service - Secure secret management with caching support
  • AES CBC Encryption Service - Encrypt and decrypt data using AES CBC with HMAC verification
  • Password Hasher Service - Secure password hashing using BCrypt
  • SMTP Service - Send emails via Microsoft Graph API (Exchange Online)
  • Cache Service - In-memory caching with expiration support
  • String Extensions - Helper methods for file path formatting

Installation

Install the package via NuGet Package Manager:

Install-Package Thuro.Utility

Or via .NET CLI:

dotnet add package Thuro.Utility

Requirements

  • .NET Standard 2.0 or higher
  • Azure services (for Azure-related features)
  • Microsoft Graph API credentials (for email functionality)

Usage

Azure Blob Storage Service

using Thuro.Utility.Services;

var blobService = new BlobService(connectionString, containerName);

// Upload a file
var stream = File.OpenRead("path/to/file.pdf");
var blobUrl = await blobService.UploadStreamToBlobAsync(stream, "folder/file.pdf");

// Download a file
var downloadedStream = await blobService.GetBlobStreamAsync("folder/file.pdf");

// Delete a file
await blobService.DeleteBlobAsync("folder/file.pdf");

// Generate SAS token
var sasToken = blobService.GenerateSasToken("folder/file.pdf", expiryMinutes: 60);

Azure Key Vault Service

using Thuro.Utility.Services;
using Microsoft.Extensions.DependencyInjection;

// Register cache service
services.AddMemoryCacheService();

// Configure Key Vault options
var options = new AzureKeyVaultService.AzureKeyVaultOptions
{
    VaultName = "your-key-vault-name",
    Keys = "Secret1,Secret2,Secret3" // Optional: specific keys, or leave empty for all
};

var cacheService = services.BuildServiceProvider().GetService<ICacheService>();
var keyVaultService = new AzureKeyVaultService(cacheService, options);

// Initialize (loads and caches secrets)
await keyVaultService.InitializeAsync();

// Get a secret
var secret = keyVaultService.GetSecret("SecretName");

// Get all secrets
var allSecrets = await keyVaultService.GetAllSecretsAsync();

AES CBC Encryption Service

using Thuro.Utility.Services;

// Generate a 64-byte key (32 bytes for AES key + 32 bytes for HMAC key)
byte[] key = new byte[64];
using (var rng = System.Security.Cryptography.RandomNumberGenerator.Create())
{
    rng.GetBytes(key);
}

// Encrypt
string plaintext = "Sensitive data";
byte[] encrypted = AesCbcEncryptionService.Encrypt(plaintext, key);

// Decrypt
string decrypted = AesCbcEncryptionService.Decrypt(encrypted, key);

// Get last 4 digits of SSN
string last4 = AesCbcEncryptionService.GetLast4Digits("123-45-6789");

Password Hasher Service

using Thuro.Utility.Services;

string password = "userPassword123";
string pepper = "your-pepper-value";

// Hash password
string hashedPassword = PasswordHasherService.HashPassword(password, pepper);

// Verify password
bool isValid = PasswordHasherService.VerifyPassword(password, hashedPassword, pepper);

SMTP Service (Microsoft Graph API)

using Thuro.Utility.Services;
using System.Net.Mail;

// Configure Key Vault options (must include Graph credentials)
var keyVaultOptions = new AzureKeyVaultService.AzureKeyVaultOptions
{
    VaultName = "your-key-vault-name"
};

var smtpService = new SMTPService(keyVaultOptions);

// Create and send email
var mailMessage = new MailMessage
{
    From = new MailAddress("sender@domain.com"),
    Subject = "Test Email",
    Body = "<h1>Hello World</h1>",
    IsBodyHtml = true
};

mailMessage.To.Add("recipient@domain.com");

await smtpService.SendEmailAsync(mailMessage);

Cache Service

using Thuro.Utility.Services;
using Microsoft.Extensions.DependencyInjection;

// Register cache service
services.AddMemoryCacheService();

var cacheService = services.BuildServiceProvider().GetService<ICacheService>();

// Set cache with expiration
cacheService.Set("myKey", "myValue", TimeSpan.FromMinutes(30));

// Get from cache
var value = cacheService.Get<string>("myKey");

// Remove from cache
cacheService.Remove("myKey");

String Extensions

using Thuro.Utility;

// Format file path (Windows to Unix style)
string path = "C:\\Users\\Documents\\file.pdf";
string formatted = path.FormatFilePath(); // "Users/Documents/file.pdf"

// Remove filename from path
string directory = "folder/subfolder/file.pdf".RemoveFileNameFromFilePath(); // "folder/subfolder/"

Dependencies

  • Azure.Identity (1.13.2)
  • Azure.Security.KeyVault.Secrets (4.7.0)
  • Azure.Storage.Blobs (12.24.0)
  • BCrypt.Net-Next (4.0.3)
  • NLog (5.4.0)
  • Microsoft.Extensions.Caching.Memory (2.2.0)
  • Microsoft.Extensions.DependencyInjection (2.2.0)
  • Microsoft.Extensions.Options (2.2.0)
  • Microsoft.Graph (5.47.0)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Thuro

Version

Current version: 1.2.0

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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.

Version Downloads Last Updated
1.2.1 201 2/17/2026
1.2.0 123 2/14/2026
1.1.6 506 6/10/2025
1.1.5 166 6/8/2025
1.1.4 235 5/29/2025
1.1.3 276 5/22/2025
1.1.2 358 5/6/2025
1.1.1 140 5/3/2025
1.1.0 152 5/2/2025
1.0.23 172 5/2/2025
1.0.22 146 5/2/2025
1.0.21 153 5/2/2025
1.0.20 156 5/2/2025
1.0.19 264 4/7/2025
1.0.18 213 4/7/2025
1.0.17 224 4/7/2025
1.0.16 220 4/7/2025
1.0.15 210 4/7/2025
1.0.14 224 4/7/2025
1.0.13 152 4/5/2025
Loading failed