I have a school project in which the text content of an HTML document is encrypted without changing its layout. Then the encrypted HTML file is sent to an Android device where it is decrypted and displayed.
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/decrypted text (2). I finished the encryption part in C#, thanks to
this source [
^]. Now I get trouble in using regex and AES decryption in Java.
Here's the decryption code in C# :
public string DecryptSpanContent(AESEncryption aes)
{
string text = Text;
string pattern = "<span style=(?<style>.*?)>(?<content>.*?)</span>";
text = Regex.Replace(text, pattern,
m => "<span style=" + m.Groups["style"] + ">" + Decrypt(m.Groups["content"].Value) + "</span>");
return text;
}
(1) How can I write this method in Java ?
(2) AES in C# and Java is 2 different way. I encrypted a text in C# with all the parameters defined by me, and this is important. I searched for the Java AES decryption but none uses such parameters, like in C#, as the key is generated automatically. I may change the C# encryption code if that could help work with the Java decryption code, but now I haven't got any solution yet.
Can anyone help me with these 2 problems, please? Thanks a lot.
Update: Problem 2 was solved. For the problem 1, I suppose the test code below works:
Pattern pattern = Pattern.compile("<span style=(.*?)>(.+?)</span>");
Matcher m = pattern.matcher(the_html_text);
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, "<span style=" + m.group(1) + ">" + aesInstance.doDecrypt(m.group(2)) + "</span>");
}
m.appendTail(sb);
Anyway, thanks for ur attention to my questions.