public void VisitPlaceholderTag(IPlaceholderTag tag)
        {
            if (tag.Properties.MetaDataContainsKey("Anonymizer"))
            {
                var abstractMarkupData = tag.Parent.AllSubItems.FirstOrDefault(i => i.IndexInParent.Equals(tag.IndexInParent));
                if (abstractMarkupData != null)
                {
                    //if we catch an exception that means is only a taged text is not encrypted
                    try
                    {
                        var decryptedText = _factory.CreateText(
                            _propertiesFactory.CreateTextProperties(AnonymizeData.DecryptData(tag.Properties.TagContent, "Andrea")));

                        var elementContainer = abstractMarkupData.Parent;

                        elementContainer.Insert(tag.IndexInParent, decryptedText);

                        elementContainer.RemoveAt(tag.IndexInParent);
                    }
                    catch (Exception e)
                    {
                        // take the text from tag and insert it back as IText
                        var elementContainer = abstractMarkupData.Parent;
                        var untagedText      = _factory.CreateText(
                            _propertiesFactory.CreateTextProperties(tag.Properties.TagContent));
                        elementContainer.Insert(tag.IndexInParent, untagedText);

                        elementContainer.RemoveAt(tag.IndexInParent);
                    }
                }
            }
        }
Exemple #2
0
 private string Process(Match match)
 {
     if (match.Success)
     {
         if (match.ToString().Contains("{") && match.ToString().Contains("}"))
         {
             var encryptedText = match.ToString().Substring(1, match.ToString().Length - 2);
             var decryptedText = AnonymizeData.DecryptData(encryptedText, "Andrea");
             return(decryptedText);
         }
     }
     return(match.ToString());
 }
Exemple #3
0
        private string ProcessMatchData(Match match, RegexPattern pattern, bool isTagContent)
        {
            var encryptedText = string.Empty;

            //Check if the match should be encrypted
            encryptedText = pattern.ShouldEncrypt ? AnonymizeData.EncryptData(match.ToString(), "Andrea") : match.ToString();
            //For tag content we need to add {} for decrypting the data
            if (isTagContent)
            {
                return(string.Concat("{", encryptedText, "}"));
            }

            return(encryptedText);
        }
Exemple #4
0
        public void VisitPlaceholderTag(IPlaceholderTag tag)
        {
            if (tag.Properties.MetaDataContainsKey("Anonymizer"))
            {
                var abstractMarkupData = tag.Parent.AllSubItems.FirstOrDefault(i => i.IndexInParent.Equals(tag.IndexInParent));
                if (abstractMarkupData != null)
                {
                    var decryptedText = _factory.CreateText(
                        _propertiesFactory.CreateTextProperties(AnonymizeData.DecryptData(tag.Properties.TagContent, "Andrea")));
                    var elementContainer = abstractMarkupData.Parent;

                    elementContainer.Insert(tag.IndexInParent, decryptedText);

                    elementContainer.RemoveAt(tag.IndexInParent);
                }
            }
        }
        private List <AnonymizedData> GetAnonymizedData(string segmentText)
        {
            var anonymizedData = new List <AnonymizedData>();

            foreach (var pattern in _patterns)
            {
                var regex   = new Regex(pattern, RegexOptions.IgnoreCase);
                var matches = regex.Matches(segmentText);
                foreach (Match match in matches)
                {
                    var data = new AnonymizedData
                    {
                        MatchText = match.Value,
                        PositionInOriginalText = match.Index,
                        EncryptedText          = AnonymizeData.EncryptData(match.ToString(), "Andrea")
                    };
                    anonymizedData.Add(data);
                }
            }
            return(anonymizedData);
        }
        private static string Process(Match match)
        {
            var encryptedText = AnonymizeData.EncryptData(match.ToString(), "Andrea");

            return(string.Concat("{", encryptedText, "}"));
        }
        private void GetSubsegmentPi(IText segmentText, List <IAbstractMarkupData> segmentContent, List <AnonymizedData> anonymizedDataList)
        {
            //this means we have PI data + text
            if (segmentText.Properties.Text.Length > anonymizedDataList[0].MatchText.Length)
            {
                //check if PI data is on first position split the segment after the PI
                if (anonymizedDataList[0].PositionInOriginalText.Equals(0))
                {
                    var remainingSegmentText = segmentText.Split(anonymizedDataList[0].MatchText.Length);
                    var tag = _factory.CreatePlaceholderTag(
                        _propertiesFactory.CreatePlaceholderTagProperties(
                            AnonymizeData.EncryptData(segmentText.Properties.Text, "Andrea")));
                    tag.Properties.SetMetaData("Anonymizer", "Anonymizer");
                    //Add encrypted tag to collection
                    segmentContent.Add(tag);

                    if (ShouldAnonymize(remainingSegmentText.Properties.Text))
                    {
                        var remainingData = GetAnonymizedData(remainingSegmentText.Properties.Text);
                        GetSubsegmentPi(remainingSegmentText, segmentContent, remainingData);
                    }
                    else
                    {
                        segmentContent.Add(remainingSegmentText);
                    }
                }
                else
                {
                    var remainingSegmentText = segmentText.Split(anonymizedDataList[0].PositionInOriginalText);
                    if (ShouldAnonymize(segmentText.Properties.Text))
                    {
                        var remainingData = GetAnonymizedData(segmentText.Properties.Text);
                        GetSubsegmentPi(segmentText, segmentContent, remainingData);
                    }
                    else
                    {
                        segmentContent.Add(segmentText);
                    }
                    if (ShouldAnonymize(remainingSegmentText.Properties.Text))
                    {
                        var remainingData = GetAnonymizedData(remainingSegmentText.Properties.Text);
                        GetSubsegmentPi(remainingSegmentText, segmentContent, remainingData);
                    }
                    else
                    {
                        var tag = _factory.CreatePlaceholderTag(
                            _propertiesFactory.CreatePlaceholderTagProperties(
                                AnonymizeData.EncryptData(remainingSegmentText.Properties.Text, "Andrea")));
                        tag.Properties.SetMetaData("Anonymizer", "Anonymizer");
                        segmentContent.Add(tag);
                    }
                }
            }             //segment contains only PI data
            else
            {
                var tag = _factory.CreatePlaceholderTag(
                    _propertiesFactory.CreatePlaceholderTagProperties(
                        AnonymizeData.EncryptData(segmentText.Properties.Text, "Andrea")));
                tag.Properties.SetMetaData("Anonymizer", "Anonymizer");
                segmentContent.Add(tag);
            }
        }