Click here to Skip to main content
14,865,287 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
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
C#
private void Test()
{
    Encoding iso = Encoding.GetEncoding("ISO-8859-1");
    //Decoder is a custom class I wrote to decode the URL
    //the same way it was url encoded in VBscript/asp
    File.WriteAllText("test.txt",
        Decoder.URL(txt_UrlEncodedStr.Text), iso);
}

//string in file contains this: Œ
//see -> http://www.fileformat.info/info/unicode/char/0152/index.htm


*Does Not Work - not wrote to file
C#
private void Test()
{
    Encoding iso = Encoding.GetEncoding("ISO-8859-1");
    //Decoder is a custom class I wrote to decode the URL
    //the same way it was url encoded in VBscript/asp
    File.WriteAllText("test.txt",
        Decoder.URL(txt_UrlEncodedStr.Text), iso);

    string result = File.ReadAllText("test.txt",
        Decoder.URL(txt_URLEncodedStr.Text), iso);

}

//Result string contains a capitalized Œ,
//which throws off the RC4 decryption.
//it wont let me paste the 'larger' Πinto here...
//see -> http://www.fileformat.info/info/unicode/char/008c/index.htm


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!
Posted
Comments
Sergey Alexandrovich Kryukov 19-Jul-13 14:51pm
   
You mess up several unrelated things: RC4, which is really the encryption, and encoding and URL encoding, which are not. And it's still unclear how did you write the file. Why using URL encoding in the file, ever? When you show "working", you don't show consisting writing and reading methods... And so on... It's called "garbage in — garbage out". Even if you have some reasonable content.
—SA
bgabel12 19-Jul-13 15:02pm
   
Thanks for the reply Sergey. Sorry for the confusion. So what I'm getting from you is that the decryption is failing and I'm trying to just work around it? Which I had that feeling. What I'm trying to do is decrypt the vbscript version of RC4 in C#. I can post my C# URL decode and C# rc4 decryption if that would be of some help? I'm new to working with encryption's tbh.

Basically the vbscript made the encryption and dumped it into MS SQL, then i'll grab it from SQL and try to decrypt it. The files are just something I was playing around with trying to troubleshoot/learn. I did feel like I was going down the wrong road for a long time, but kept hammering away at it.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900