I want to encrypt the text content of an HTML Document without changing its layout. The content is stored in pairs of tag , like this : < span style...>text_to_get< /span>. My idea is using Regex to retrieve (1) and to replace each text part with the encrypted text (2). I complete step (1) but have trouble at step (2) . Here is the code I'm working on :
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;
}
Is this the wrong line (that makes all the texts replaced by the last replaceWith value) ?
resultText = regex.Replace(resultText, replaceWith);
Can anybody help me to fix this ?