0

I'm working on a C# encryption program, and I am pretty much done with it.

It encrypts and decrypts a string that I pass as an argument.

The only problem is that when I compare to equivalent Java encryption program I notice that c# converts hexadecimal of special characters.

Is there a way I can tell the program not to convert special characters and just represent them as hexadecimal?

Here is an example

Java :

4g8LAQXy%2B1M%3D

C#:

4g8LAQXy+1M=

As you can see, '+' in hex is 2B and '=' in hex is 3D.

6
  • 5
    I hope you aren't using Base64 as an encryption scheme Commented Feb 4, 2014 at 16:17
  • % should not appear in Base64 output, the Java result looks URL encoded? where does it come from? Commented Feb 4, 2014 at 16:19
  • 1
    To tag onto @DGibbs, Base64 is not encryption - it is encoding. Base64 is no better than plaintext. Just want to make sure that was clear. Commented Feb 4, 2014 at 16:21
  • I'm emulating PBEwith md5 and des c#. sorry i wasn't clear in the op Commented Feb 4, 2014 at 16:50
  • I have changed the title of the question to ensure base64 is not being confused with encryption. Commented Feb 4, 2014 at 16:57

1 Answer 1

1

That looks like url % encoding, not base-64; have you tried HttpUtility.UrlEncode() ?

string s = "4g8LAQXy+1M=";
string t = HttpUtility.UrlEncode(s); // 4g8LAQXy%2b1M%3d
Sign up to request clarification or add additional context in comments.

4 Comments

@user that method goes all the way back to 2.0 - just add a reference to System.Web.dll; or alternatively just write it yourself - it is pretty trivial to do (we use a custom one, IIRC)
Is there a way for the %2b to be %2B? same for the %3d
@user well, in url-encode terms they are identical. You could hand-roll the encode, though - it is mainly "check the whitelist, check if it is outside the ascii range; if so, utf-8 encode and hex encode that
Thanks for the tip. I approached it a little differently. I just looked for the % and just uppercased the following two characters. It worked as I intended.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.