EncineCarlos.Obfuscator 1.0.0

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

EncineCarlos.Obfuscator

NuGet Version NuGet Downloads License: MIT

A powerful and easy-to-use .NET library for obfuscating sensitive data in your applications. Automatically redacts properties marked with [SensitiveData] attribute using the Microsoft Extensions Compliance framework.

Features

Attribute-based Obfuscation: Simply mark properties with [SensitiveData] attribute
Nested Object Support: Recursively processes complex object hierarchies
JSON Serialization: Returns clean JSON with sensitive data redacted
JsonPropertyName Support: Respects [JsonPropertyName] attributes
Microsoft Extensions Integration: Built on Microsoft.Extensions.Compliance framework
Dependency Injection Ready: Easy integration with .NET DI container
High Performance: Minimal overhead with reflection caching

Installation

dotnet add package EncineCarlos.Obfuscator

Quick Start

1. Mark sensitive properties with [SensitiveData]

public class User
{
    public string Name { get; set; }
    
    [SensitiveData]
    public string Email { get; set; }
    
    [SensitiveData]
    public string Password { get; set; }
    
    public int Age { get; set; }
    
    [SensitiveData]
    public decimal Salary { get; set; }
}

2. Register the service in your DI container

// Program.cs or Startup.cs
services.AddObfuscator();

3. Use the obfuscator service

public class MyController : ControllerBase
{
    private readonly IObfuscatorService _obfuscator;
    
    public MyController(IObfuscatorService obfuscator)
    {
        _obfuscator = obfuscator;
    }
    
    public IActionResult GetUser()
    {
        var user = new User
        {
            Name = "John Doe",
            Email = "john@example.com",
            Password = "secret123",
            Age = 30,
            Salary = 75000.50m
        };
        
        // Obfuscate sensitive data before logging or returning
        var obfuscatedData = _obfuscator.ObfuscateSensitiveData(user);
        
        _logger.LogInformation("User data: {UserData}", obfuscatedData);
        
        return Ok(obfuscatedData);
    }
}

Output

{
  "Name": "John Doe",
  "Email": "[REDACTED]",
  "Password": "[REDACTED]",
  "Age": 30,
  "Salary": "[REDACTED]"
}

Advanced Usage

Nested Objects

The library automatically handles nested objects:

public class User
{
    public string Name { get; set; }
    
    [SensitiveData]
    public string Email { get; set; }
    
    public Address Address { get; set; }
}

public class Address
{
    public string Street { get; set; }
    
    [SensitiveData]
    public string CreditCardNumber { get; set; }
    
    public string City { get; set; }
}

JsonPropertyName Support

Respects [JsonPropertyName] attributes for consistent JSON output:

public class User
{
    [JsonPropertyName("full_name")]
    public string Name { get; set; }
    
    [SensitiveData]
    [JsonPropertyName("email_address")]
    public string Email { get; set; }
}

Manual Usage (without DI)

var redactorProvider = new SimpleRedactorProvider();
var obfuscator = new ObfuscatorService(redactorProvider);

var result = obfuscator.ObfuscateSensitiveData(myObject);

Use Cases

  • Logging: Remove sensitive data from logs
  • API Responses: Clean data before sending to clients
  • Debugging: Safe object inspection in development
  • Compliance: GDPR, HIPAA, and other privacy regulations
  • Data Export: Sanitize data for reports or analytics

Configuration

The library uses Microsoft.Extensions.Compliance for redaction. You can customize the redaction behavior:

services.AddRedaction(builder =>
{
    builder.SetRedactor<MyCustomRedactor>(new DataClassificationSet());
});

Performance

The library is optimized for performance:

  • Uses reflection caching internally
  • Minimal memory allocations
  • Supports high-throughput scenarios

Requirements

  • .NET Standard 2.1 or higher
  • Microsoft.Extensions.Compliance.Abstractions 9.8.0+
  • Microsoft.Extensions.Compliance.Redaction 9.8.0+

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

Support

If you encounter any issues or have questions, please open an issue on GitHub.


Made with ❤️ by Encine Carlos

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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.0.0 200 9/10/2025

v1.0.0:
- Initial release with full obfuscation functionality
- Support for JsonPropertyName attribute in property serialization
- Enhanced nested object handling for complex data structures
- Improved redaction capabilities using Microsoft Extensions Compliance
- Complete integration with dependency injection container
- Attribute-based obfuscation with [SensitiveData] marking