Beispiel #1
0
        static void Main(string[] args)
        {
            var creditCardMasker = new Masker()
            {
                Pattern = "************####", Size = 16
            };
            var passwordMasker = new Masker()
            {
                Pattern = "****************", Size = 16
            };

            var cc1 = creditCardMasker.Mask("1234567890123456");
            var cc2 = creditCardMasker.Mask("123456789012345");

            var test = new MyTestClass()
            {
                CardNumber  = "1234567890123456",
                Password    = "******",
                Description = "way too long"
            };

            ILogFilter <MyTestClass> filter =
                new LogFilter <MyTestClass>()
                .Ignore(f => f.Description)
                .Obfuscate(f => f.Password, passwordMasker)
                .Obfuscate(f => f.CardNumber, creditCardMasker);

            ILogFilter <MyTestClass2> filter2 =
                new LogFilter <MyTestClass2>()
                .Ignore(f => f.Description)
                .Obfuscate(f => f.Password, passwordMasker)
                .Obfuscate(f => f.CardNumber, creditCardMasker);

            Add(filter);
            Add(filter2);

            var resolver = new IgnoreObfuscateContractResolver <MyTestClass>(filter);
            var settings = new JsonSerializerSettings {
                ContractResolver = resolver
            };
            var result = JsonConvert.SerializeObject(test, settings);

            Console.ReadKey();
        }
 public ObfuscateProvider(MemberInfo memberInfo, Masker masker)
 {
     _underlyingValueProvider = new DynamicValueProvider(memberInfo);
     _masker = masker;
 }
Beispiel #3
0
 public ILogFilter <T> Obfuscate(Expression <Func <T, object> > func, Masker masker)
 {
     //need to work out what to do with the mask
     PropertyObfuscaters.Add(func, masker);
     return(this);
 }