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 key = AnonymizeData.EncryptData(_decryptSettings.EncryptionKey, Constants.Key); var decryptedText = _factory.CreateText( _propertiesFactory.CreateTextProperties( AnonymizeData.DecryptData(tag.Properties.TagContent, _decryptSettings.EncryptionKey))); if (!_decryptSettings.IgnoreEncrypted) { 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 InsertTextBack(abstractMarkupData, tag); } } } }
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) { string encryptedText; //Check if the match should be encrypted 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 List <AnonymizedData> GetAnonymizedData(string segmentText) { var anonymizedData = new List <AnonymizedData>(); foreach (var pattern in _patterns) { var regex = new Regex(pattern.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(), _encryptionKey) }; anonymizedData.Add(data); } } return(anonymizedData); }
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); try { //var key = AnonymizeData.EncryptData(_decryptSettings.EncryptionKey, Constants.Key); var decryptedText = AnonymizeData.DecryptData(encryptedText, _decryptSettings.EncryptionKey); if (!_decryptSettings.IgnoreEncrypted) { return(decryptedText); } } catch (Exception e) { return(encryptedText); } } } return(match.ToString()); }
private Regex DecryptIfEncrypted(RegexPattern pattern) { return(new Regex(!_arePatternsEcrypted ? pattern.Pattern : AnonymizeData.DecryptData(pattern.Pattern, _encryptionKey), RegexOptions.IgnoreCase)); }