我想加密HTML文档中的文本内容,而不改变其布局。内容以标签对形式存储,如下所示:<span style...>text_to_get</span>。我的想法是使用正则表达式检索(1),并将每个文本部分替换为加密文本(2)。我已经完成了步骤(1),但在步骤(2)中遇到了问题。以下是我正在处理的代码:
private string encryptSpanContent(string text, string passPhrase, string salt, string hash, int iteration, string initialVector, int keySize)
{
string resultText = text;
string pattern = "<span style=(?<style>.*?)>(?<content>.*?)</span>";
Regex regex = new Regex(pattern);
MatchCollection matches = regex.Matches(resultText);
foreach (Match match in matches)
{
string replaceWith = "<span style=" + match.Groups["style"] + ">" + AESEncryption.Encrypt(match.Groups["content"].Value, passPhrase, salt, hash, iteration, initialVector, keySize) + "</span>";
resultText = regex.Replace(resultText, replaceWith);
}
return resultText;
}
这是错误的语句(会导致所有文本都被最后一个replaceWith值替换)吗?
resultText = regex.Replace(resultText, replaceWith);
有人能帮我解决这个问题吗?