Click here to Skip to main content
11,411,312 members (70,151 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Java HTML RegEx
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=" + + ">" + aesInstance.doDecrypt( + "</span>");

Anyway, thanks for ur attention to my questions.
Posted 3-May-12 23:17pm
Edited 15-May-12 5:12am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


you can use Java Cryptography Extension (JCE) to pass special parameters as in C#,
writing the method is your homework Wink | ;) .[^][^]

Does it help?

Best Regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 149
1 Sascha Lefévre 110
2 OriginalGriff 103
3 Dave Kreskowiak 80
4 Maciej Los 78
0 Sergey Alexandrovich Kryukov 8,920
1 OriginalGriff 6,983
2 Maciej Los 3,430
3 Abhinav S 3,248
4 Peter Leow 3,059

Advertise | Privacy | Mobile
Web02 | 2.8.150414.5 | Last Updated 15 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100