简体   繁体   中英

C# string encoding using ToBase64String

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM