0

So, I have some code here that compares MD5 Hashes to ones on a webserver Not in a .php file or anything just a plain .txt Heres the code

        WebClient wc = new WebClient();
        var md5signatures = wc.DownloadString("http://examplesite/MD5base.txt");
        if (md5signatures.Contains("9801b7c917063b8b36f8de97098e9c66"))
        {
            StatusLabel.Text = "MD5 Found In Website";
            StatusLabel.ForeColor = Color.Green;
        }
        else
        {
            StatusLabel.Text = "MD5 Not Found In Website";
            StatusLabel.ForeColor = Color.Red;
        }

Here is the .txt that is in my website (im using examplesite as an example obviously, not the real code)

e787763e761b600730c38b3c47d62f2b
3ba70d4dcaf1817cac0feb0cb2cd26c0
42ba439f8b3fb128de98fd8a54afcc90
2d8413cfd8ed5e5a531bed229fabd8a0
53e2229ce9e603653f251f5c1e686da0
9801b7c917063b8b36f8de97098e9c66
47eb494feb0ba8b754ddc307b74b6ac0
3baa5dc9aaf6afc704d9da1469b15080

I Did this exact program with a .txt file on the drive and it worked perfectly no issues (I Think its because i used File.ReadAllLines which ill get to in a moment)

But when i upload the same .txt file to a webserver things get a ton more complicated actually The reason i think this is happening is due to the fact that WebClient has no control for reading things line by line, All i know of is DownloadString which im pretty sure puts the hashes right next to eachother like so

Instead of

e787763e761b600730c38b3c47d62f2b
3ba70d4dcaf1817cac0feb0cb2cd26c0

Its

3ba6e302c6d872dc8bf71050e9f4c2f0e787763e761b600730c38b3c47d62f2b

Two hashes kind of appended to eachother

Any help would be greatly appreciated as ive been stumped on this for a while If im incorrect about anything here please let me know.

Max Andrews
  • 21
  • 1
  • 3
  • have you tried https://stackoverflow.com/a/26928354/361100 approach for newline treatment? – Youngjae Jan 02 '20 at 02:47
  • 1
    WebClient downloads the file content as it is. If it has line feeds, the resulting string will contain line feeds, the same as the original text file. But, you're using `md5signatures.Contains(...)`, so the line feed type doesn't matter much. If you want to convert the string in an array of strings, split on both `\n` and `\r`, removing empty results (i.e., `StringSplitOptions.RemoveEmptyEntries`). – Jimi Jan 02 '20 at 02:50
  • So your file doesn't contain any `0x10` or `0x13` bytes? How did you upload this file? Have you tried reading the string with Visual Studio's default Text Viewer in debug mode? EDIT: All right, comment deleted. Did you inspect the resulting string again, finding different evidence? – Jimi Jan 02 '20 at 02:56
  • Sorry, but what do you mean by viewing it in debug mode? i open it in the text editor and it just looks the same to me :/ im probably missing something. I am opening in visual studio, by the way – Max Andrews Jan 02 '20 at 03:00
  • When you debug your code, add a breakpoint in line after `var md5signatures = wc.DownloadString(...)` (the `if` condition, or insert `Console.WriteLine(md5signatures)` in between) . Then hover `md5signatures` with the mouse pointer, see the lens that appear, click on the down arrow and select `Text Visualizer`. See what it shows. But, as alredy mentioned, you're using `Contains()`: if the string is there, you'll find it anyway. There's also a matter related to the encoding: WebClient, by default, uses `Encoding.Default` to read the response. – Jimi Jan 02 '20 at 03:05
  • Alright, got it working! Thank you, this is what appeared in the text visualizer. Just a screenshot since copy and pasting its too big for a comment. If you need it in text for whatever reason tell me. http://prntscr.com/qibnid – Max Andrews Jan 02 '20 at 03:19
  • ···string[] strArr = md5signatures.Split(new[] { "\r\n" },StringSplitOptions.RemoveEmptyEntries);··· – Han Heong Ho Jan 02 '20 at 03:30
  • That code does not work unfourtunately – Max Andrews Jan 02 '20 at 03:53
  • Try split using refex for example https://stackoverflow.com/questions/1508203/best-way-to-split-string-into-lines – apincik Jan 02 '20 at 08:45

0 Answers0