JsonDataMasking 2.0.1

dotnet add package JsonDataMasking --version 2.0.1
NuGet\Install-Package JsonDataMasking -Version 2.0.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="JsonDataMasking" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonDataMasking --version 2.0.1
#r "nuget: JsonDataMasking, 2.0.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.
// Install JsonDataMasking as a Cake Addin
#addin nuget:?package=JsonDataMasking&version=2.0.1

// Install JsonDataMasking as a Cake Tool
#tool nuget:?package=JsonDataMasking&version=2.0.1

NuGet Version CI

JSON Data Masking

JSON Data Masking is a library for .NET Core applications that simplifies the masking process of PII/sensitive information.

Usage

After installing the Nuget package in your project, you need to take the following steps:

  1. Add the [SensitiveData] attribute in your class properties to indicate what should be masked, and use its available fields to configure the masking:

    • PreserveLength: Set to true to keep the property length when masking its value. By default this setting is set to false.
    • ShowFirst: If set, shows the first N characters of the property, not masking them. The default value is 0.
    • ShowLast: If set, shows the last N characters of the property, not masking them. The default value is 0.
    • SubstituteText: If set, the entire property value will be override with this text. Note that using this setting will ignore all other settings.
    • Mask: Set to a character to use it when masking the property's value. By default, the character * is used.
  2. Call the JsonMask.MaskSensitiveData() function, passing in your object instance as a parameter.

Support

This library supports masking of string fields only, although it also supports List<string>/IEnumerable<string> and Dictionary<string, string>. Nested class properties are also masked, independently of depth.

Property Type Support
string
List<T>, where T is a class or string
IEnumerable<T>, where T is a class or string
Dictionary<string, string>
Any other collection type, such as Array, ArrayList<T>, etc
Any other base type different from string

Examples

Attributes

public class PropertiesExamples
{
    /// 123456789 results in "*****"
    [SensitiveData]
    public string DefaultMask { get; set; }

    /// 123456789 results in "REDACTED"
    [SensitiveData(SubstituteText = "REDACTED")]
    public string SubstituteMask { get; set; }

    /// 123456789 results in "123*****789"
    [SensitiveData(ShowFirst = 3, ShowLast = 3)]
    public string ShowCharactersMask { get; set; }

    /// 123456789 results in "#########"
    [SensitiveData(PreserveLength = true, Mask = "#")]
    public string PreserveCustomMask { get; set; }
}

Functions

var maskedData = JsonMask.MaskSensitiveData(data);

Dependencies

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. 
.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.

Version Downloads Last updated
2.0.1 6,660 3/18/2023
2.0.0 7,948 11/3/2022
1.2.2 1,712 7/21/2022