private List <AnonymizedData> GetAnonymizedData(string segmentText)
        {
            var anonymizedData = new List <AnonymizedData>();

            foreach (var pattern in _patterns)
            {
                var regex   = DecryptIfEncrypted(pattern);
                var matches = regex.Matches(segmentText);
                foreach (Match match in matches)
                {
                    if (match.Value.Length > 0)
                    {
                        var data = new AnonymizedData
                        {
                            MatchText = match.Value,
                            PositionInOriginalText = match.Index,
                            EncryptedText          = AnonymizeData.EncryptData(match.ToString(), _encryptionKey)
                        };

                        anonymizedData.Add(data);
                    }
                }
            }
            return(anonymizedData);
        }
        private string DecryptText(string encryptedText)
        {
            var isOldVersion = _decryptSettings.IsOldVersion ?? false;
            var encryptedKey = _decryptSettings.EncryptionKey;
            var decryptedKey = AnonymizeData.DecryptData(encryptedKey, Constants.Key);

            var key = isOldVersion ? encryptedKey : decryptedKey;

            _decryptSettings.IsOldVersion = false;
            return(AnonymizeData.DecryptData(encryptedText, key));
        }
        private string ProcessMatchData(Match match, RegexPattern pattern, bool isTagContent)
        {
            //Check if the match should be encrypted
            var encryptedText = pattern.ShouldEncrypt ? AnonymizeData.EncryptData(match.ToString(), _encryptionKey) : match.ToString();

            //For tag content we need to add {} for decrypting the data
            if (isTagContent)
            {
                return(string.Concat("{", encryptedText, "}"));
            }

            return(encryptedText);
        }
 private Regex DecryptIfEncrypted(RegexPattern pattern)
 {
     return(new Regex(!_arePatternsEcrypted ? pattern.Pattern : AnonymizeData.DecryptData(pattern.Pattern, _encryptionKey), RegexOptions.IgnoreCase));
 }