Issue: Unable to store the exact same characters into a string variable.
Basically I have passwords that are RC4 encrypted and then url encoded before they are stored into the database. This process was done in classic asp/vbscript. This process was also not done by me. I do have access to the source code, but this isn't the issue atm. (at least I hope not)
What I need to accomplish: I'm trying to take the stored encrypted/encoded passwords and decode/decrypt them for usage.
Note: Both my URL Decoding and RC4 Decryption is working fine based on my testing.
The problem at hand: So the issue right now seems to be an encoding issue. Through a very time consuming process of trying to identify what was going on with my url decode which was giving question marks mixed inside the decoded string, I discovered that the encoding was different. Again through testing, I figured out that the encoding of the string was ISO-8859-1.
The only way I could get the output of the URL decode to work as expected was to write the Url decoded string to a .txt file setting the files Encoding to ISO-8859-1
Here is the URL encoded string I'm starting out with: 0H%BA%DFb%8C%16%14
*Works - gives the correct string in the text file
private void Test()
{
Encoding iso = Encoding.GetEncoding("ISO-8859-1");
File.WriteAllText("test.txt",
Decoder.URL(txt_UrlEncodedStr.Text), iso);
}
*Does Not Work - not wrote to file
private void Test()
{
Encoding iso = Encoding.GetEncoding("ISO-8859-1");
File.WriteAllText("test.txt",
Decoder.URL(txt_UrlEncodedStr.Text), iso);
string result = File.ReadAllText("test.txt",
Decoder.URL(txt_URLEncodedStr.Text), iso);
}
At this point I was thinking, 'well why not just read straight from the file into my RC4 Decryption' well that didn't work either...
It somehow alters the encoding and throws the RC4 decryption off.
When I copy and paste the string from the text file and run the decryption, it works fine.
M89teÆfo <-- Incorrect from reading the file within code.
M89teufo <-- Correct by copy from the text file and pasting
it into a textbox and running the decryption.
I've spent a bunch of time on this and would appreciate any help. I'm trying to keep it all in C#. Yes I could get it working by creating a vbscript to decrypt/decode the passwords and place them into a text file that I could read into C# code and delete the file when I'm done with it, but how would I learn anything? :). Thanks in advance!