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 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)); }