Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A fast, simple, zero allocation redacting library for .NET, with no non-Microsoft dependencies.

License

NotificationsYou must be signed in to change notification settings

nikouu/ZeroRedact

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NuGet DownloadsNuGetGitHub ReleaseOfficial DocsDemoGitHub LicenseBlog

A fast, simple, zero allocation redacting library for .NET, with no non-Microsoft dependencies.

Fully or partially redact:

  • Strings
  • Email addresses
  • Credit card numbers
  • Dates
  • Phone numbers
  • IPV4 addresses
  • IPV6 addresses
  • MAC addresses

Read more in theofficial docs.

Getting started

Install viaNuGet:

dotnet add package Nikouu.ZeroRedact

The following shows example redactions with varying configs. For more see theofficial docs.

varredactor=newRedactor();// returns "*************"varstringResult=redactor.RedactString("Hello, World!");// returns "*****@*******.***"varemailAddressResult=redactor.RedactEmailAddress("email@example.com");// returns "****-****-****-1111"varcreditCardOptions=newCreditCardRedactorOptions{RedactorType=CreditCardRedaction.ShowLastFour};varcreditCardResult=redactor.RedactCreditCard("4111-1111-1111-1111",creditCardOptions);// returns based on current culture// en-NZ: "**/06/2023"// en-US: "6/**/2023"// ja-JP: "2023/06/**"// InvariantCulture: "06/**/2023"vardateOptions=newDateRedactorOptions{RedactorType=DateRedaction.Day};vardateResult=redactor.RedactDate(newDateTime(2023,6,15),dateOptions);// returns "###-###-####"varphoneNumberOptions=newPhoneNumberRedactorOptions{RedactionCharacter='#'};varphoneNumberResult=redactor.RedactPhoneNumber("212-456-7890");// returns "@@@.@.@.146"varipv4AddressOptions=newIPv4AddressRedactorOptions{RedactionCharacter='@',RedactorType=IPv4AddressRedaction.ShowLastOctet};varipv4Result=redactor.RedactIPv4Address("192.0.2.146",ipv4AddressOptions);// returns "****:****:****:****:****:****:****:****"varipv6Result=redactor.RedactIPv6Address("2001:0000:130F:0000:0000:09C0:876A:130B");// "**:**:**:**:**:**"varmacResult=redactor.RedactMACAddress("00:B0:D0:63:C2:26");

Or in the case of a service registration withIServiceCollection:

// Defaultbuilder.Services.AddZeroRedact();// Or to configurebuilder.Services.AddZeroRedact(newRedactorOptions{CreditCardRedactorOptions=newCreditCardRedactorOptions{RedactorType=CreditCardRedaction.ShowLastFour},EmailAddressRedactorOptions=newEmailAddressRedactorOptions{RedactorType=EmailAddressRedaction.ShowFirstCharacters},DateRedactorOptions=newDateRedactorOptions{RedactorType=DateRedaction.Day},PhoneNumberRedactorOptions=newPhoneNumberRedactorOptions{RedactorType=PhoneNumberRedaction.ShowLastFour}});

Configuration

ZeroRedact can be configured in two ways: via constructor, and via a redaction method. Both using the appropriate redactor option object.

Configuration has three layers with least to most priority:

  1. Base defaults within theRedactor object.
  2. Passed in options to theRedactor object constructor
  3. Passed in options to a redaction method at the time of redaction

This example shows changing the base defaults. This will apply to every redaction, whether it's a string or email address, etc.

// Example 1: Changing base defaultsvaroptions=newRedactorOptions{RedactionCharacter='X'};varredactor=newRedactor(options);// returns "XXXXXXXXXXXXX"varresult=redactor.RedactString("Hello, World!");

This example showsStringRedactorOptions being passed into theRedactor constructor. Only string redactions will now use 'A' as the redaction character, all others will continue to use the default character of '*'.

// Example 2: Changing specific redaction type optionsvaroptions=newRedactorOptions{StringRedactorOptions=newStringRedactorOptions{RedactionCharacter='A'}};varredactor=newRedactor(options);// returns "AAAAAAAAAAAAA"varresult=redactor.RedactString("Hello, World!");

This example shows passing inStringRedactorOptions at the time of redaction, which takes precedence over the constructor options.

// Example 3: Changing redaction options at redaction timevaroptions=newRedactorOptions{StringRedactorOptions=newStringRedactorOptions{RedactionCharacter='A'}};varredactor=newRedactor(options);varspecificOptions=newStringRedactorOptions{RedactionCharacter='B'};// returns "BBBBBBBBBBBBB"varresult=redactor.RedactString("Hello, World!",specificOptions);

Layered configuration

Users should have a fine grained customization experience which allows for an easy to reuse item that can setup default behaviours but when needed, can adapt to the need of the redaction call at the time.

Error handling

Redacting will not throw exceptions - that is, the string manipulation logic. Any exception during the redacting process will return a fixed length redaction with a default redacting character. This is to avoid disrupting the important real work happening in a user's codebase while still preventing PII from being exposed.

However exceptions can occur by passing invalid options to the redactor, whether that's via the constructor, or via a redaction method.

No external dependencies

Keeps project light, easier to maintain, easier to get approved by having Microsoft-only packages for less supply chain issues. Read more from Microsoft viaBest practices for a secure software supply chain.

Microsoft.Extensions.Compliance.Redaction

ZeroRedact can be integrated intoMicrosoft.Extensions.Compliance.Redaction to provide full and partial redacting.

SeeCompliance.Redaction-with-ZeroRedact for an example project.

Performance

Benchmarks

Seebenchmarks.

Contributing

Currently not looking for contributions, however issues for problems or feature suggestions are welcome for consideration.

License

MIT

About

A fast, simple, zero allocation redacting library for .NET, with no non-Microsoft dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

    Languages


    [8]ページ先頭

    ©2009-2025 Movatter.jp