简体   繁体   English

使用ToBase64String的C#字符串编码

[英]C# string encoding using ToBase64String

I'm working on a C# encryption program, and I am pretty much done with it. 我正在开发C#加密程序,并且已经完成了很多工作。

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. 唯一的问题是,当我与等效的Java加密程序进行比较时,我注意到c#转换特殊字符的十六进制。

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 : Java的:

4g8LAQXy%2B1M%3D

C#: C#:

4g8LAQXy+1M=

As you can see, '+' in hex is 2B and '=' in hex is 3D . 如您所见,十六进制的'+'2B ,十六进制的'='3D

That looks like url % encoding, not base-64; 看起来像url%编码,而不是base-64; have you tried HttpUtility.UrlEncode() ? 您是否尝试过HttpUtility.UrlEncode()

string s = "4g8LAQXy+1M=";
string t = HttpUtility.UrlEncode(s); // 4g8LAQXy%2b1M%3d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 了解ToBase64String - Understanding ToBase64String c# SHA256 ToBase64String of string 与测试用例不同 - c# SHA256 ToBase64String of string not the same as test case TObase64String 未编码我的访问令牌,导致 401 未经授权 - TObase64String not encoding my Access token , resulting to 401 unauthorized 将具有HASH MD5的字符串转换为ToBase64String - Convert string with HASH MD5 to ToBase64String 如何安全地转换块中的ToBase64String? - How to safely convert `ToBase64String` in chunks? 将大文件读入字节数组并将其编码为ToBase64String - Read large file into byte array and encode it to ToBase64String 使用ToBase64String()加密解密密码-特殊字符替换为? - Encrypt decrypt password with ToBase64String() - special characters are replaced by? ToBase64String()方法应该适用于所有图像类型吗? - Should ToBase64String() method work with all image types? 等效于MD5CryptoServiceProvider的Java算术哈希和ToBase64String - Java equivalent to MD5CryptoServiceProvider computeHash & ToBase64String LINQ to Entities无法识别方法'System.String ToBase64String(Byte [])'方法, - LINQ to Entities does not recognize the method 'System.String ToBase64String(Byte[])' method,
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM