Sayeed.NETCore.DataProtection 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sayeed.NETCore.DataProtection --version 1.0.0
NuGet\Install-Package Sayeed.NETCore.DataProtection -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="Sayeed.NETCore.DataProtection" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sayeed.NETCore.DataProtection --version 1.0.0
#r "nuget: Sayeed.NETCore.DataProtection, 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.
// Install Sayeed.NETCore.DataProtection as a Cake Addin
#addin nuget:?package=Sayeed.NETCore.DataProtection&version=1.0.0

// Install Sayeed.NETCore.DataProtection as a Cake Tool
#tool nuget:?package=Sayeed.NETCore.DataProtection&version=1.0.0

Sayeed.NETCore.DataProtection

Sayeed.NETCore.DataProtection is a library that provides a helper class for hiding sensitive properties within C# objects. It allows you to iterate over an object and identify any property names that contain sensitive keywords, and then hide their values. This library can be used to protect sensitive information within your application, such as passwords, tokens, or any other sensitive data.

Features

  • Iterate over any C# object and hide sensitive properties
  • Customizable set of sensitive keywords to match against property names
  • Customizable maximum depth of recursion loop
  • Supports classes, records, and pre-defined types (anonymous objects are not supported)

Installation

You can install the Sayeed.NETCore.DataProtection library via NuGet. Run the following command in the NuGet Package Manager Console:

Install-Package Sayeed.NETCore.DataProtection

Usage

  1. Create an instance of the Helper class, which provides various constructors to customize the behavior:
Helper helper = new Helper();
  1. Call the HideSensativeProperties method and pass the object you want to process:
MyClass myObject = new MyClass();
helper.HideSensativeProperties(myObject);

The HideSensativeProperties method will recursively iterate over the object and its properties, searching for property names that contain sensitive keywords. If a match is found, the property value will be set to null. The method modifies the existing object, don't return anything.

Customization

Custom Set of Sensitive Keywords

You can provide your own set of sensitive keywords to match against property names by using the constructor that accepts an array of strings:

string[] customKeywords = new string[] { "custom", "keywords" };
Helper helper = new Helper(customKeywords);
Maximum Depth of Recursion Loop

By default, the maximum depth of the recursion loop is set to 10. You can customize this value using the constructor that accepts an integer:

int maxDepth = 5;
Helper helper = new Helper(maxDepth);

####Custom Set of Keywords and Maximum Depth If you want to customize both the sensitive keywords and the maximum depth of the recursion loop, use the constructor that accepts both parameters:

string[] customKeywords = new string[] { "custom", "keywords" };
int maxDepth = 5;
Helper helper = new Helper(customKeywords, maxDepth);

Examples

Here's an example of using Sayeed.NETCore.DataProtection to hide sensitive properties within an object:

Helper helper = new Helper();

// Create an object with sensitive properties
MyClass myObject = new MyClass
{
    Password = "secretpassword",
    Token = "sometoken",
    Name = "John Doe"
};

// Hide sensitive properties
helper.HideSensativeProperties(myObject);

// Sensitive properties are now null
Console.WriteLine(myObject.Password); // null
Console.WriteLine(myObject.Token); // null
Console.WriteLine(myObject.Name); // "John Doe" (not sensitive)

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue on the GitHub repository.

License

This library is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgements

This library was developed by Md. Sayeed Rahman.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.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.2 280 5/27/2023
1.0.1 142 5/26/2023
1.0.0 254 5/26/2023