diff --git a/src/Particular.LicensingComponent.Report.UnitTests/ApprovalFiles/ApiApprovals.Approve.approved.txt b/src/Particular.LicensingComponent.Report.UnitTests/ApprovalFiles/ApiApprovals.Approve.approved.txt index 9401c41..6e97c6a 100644 --- a/src/Particular.LicensingComponent.Report.UnitTests/ApprovalFiles/ApiApprovals.Approve.approved.txt +++ b/src/Particular.LicensingComponent.Report.UnitTests/ApprovalFiles/ApiApprovals.Approve.approved.txt @@ -78,4 +78,16 @@ namespace Particular.LicensingComponent.Report public Particular.LicensingComponent.Report.Report ReportData { get; init; } public string Signature { get; init; } } +} +namespace Particular.LicensingComponent.Report.Utility +{ + public class Masker + { + public Masker(string[] wordsToMask) { } + public string Mask(string stringToMask) { } + } + public static class OneWayHasher + { + public static string CalculateOneWayHash(string input) { } + } } \ No newline at end of file diff --git a/src/Particular.LicensingComponent.Report/Utility/Masker.cs b/src/Particular.LicensingComponent.Report/Utility/Masker.cs new file mode 100644 index 0000000..3a8319b --- /dev/null +++ b/src/Particular.LicensingComponent.Report/Utility/Masker.cs @@ -0,0 +1,36 @@ +namespace Particular.LicensingComponent.Report.Utility; +/// +/// Provides functionality to mask specified words in a given string with unique replacement values. +/// +public class Masker +{ + readonly (string Mask, string Replacement)[] masks; + + /// + /// Initializes a new instance of the Masker class with the specified words to be masked. + /// + public Masker(string[] wordsToMask) + { + var number = 0; + masks = [.. wordsToMask + .Select(mask => + { + number++; + return (mask, $"REDACTED{number}"); + })]; + } + + /// + /// Replaces all occurrences of specified substrings in the input string with their corresponding masked values + /// using a predefined set of masks. + /// + public string Mask(string stringToMask) + { + var result = stringToMask; + foreach (var (mask, replacement) in masks) + { + result = result.Replace(mask, replacement, StringComparison.OrdinalIgnoreCase); + } + return result; + } +} \ No newline at end of file diff --git a/src/Particular.LicensingComponent.Report/Utility/OneWayHasher.cs b/src/Particular.LicensingComponent.Report/Utility/OneWayHasher.cs new file mode 100644 index 0000000..6e2fe03 --- /dev/null +++ b/src/Particular.LicensingComponent.Report/Utility/OneWayHasher.cs @@ -0,0 +1,16 @@ +namespace Particular.LicensingComponent.Report.Utility; + +using System.Security.Cryptography; +using System.Text; + +/// +/// Provides static methods for computing one-way hashes using the SHA3-256 algorithm. +/// +public static class OneWayHasher +{ + /// + /// Calculates the SHA3-256 hash of the specified input string and returns the result as a hexadecimal string. + /// + public static string CalculateOneWayHash(string input) + => BitConverter.ToString(SHA3_256.HashData(Encoding.UTF8.GetBytes(input))).Replace("-", ""); +} \ No newline at end of file