[英]Encoding in C# and Decoding in Javascript
I have encoded some text in C# like below:我在 C# 中编码了一些文本,如下所示:
var encodedCredential = Convert.ToBase64String(Encoding.Unicode.GetBytes(JsonConvert.SerializeObject("Sample text")));
The encoded String is : IgBTAGEAbQBwAGwAZQAgAHQAZQB4AHQAIgA=
编码后的字符串是:
IgBTAGEAbQBwAGwAZQAgAHQAZQB4AHQAIgA=
I want to decode the encoded String in java script.我想在 java 脚本中解码编码的字符串。
I have tried the below我已经尝试过以下
decodeURIComponent(atob("IgBTAGEAbQBwAGwAZQAgAHQAZQB4AHQAIgA="))
decodeURIComponent(atob("IgBTAGEAbQBwAGwAZQAgAHQAZQB4AHQAIgA=").replace(' ',''))
The result is something different, There are some spaces in each letter.结果有所不同,每个字母中都有一些空格。 I cant even replace the spaces.
我什至不能替换空格。
You need to use UTF-8 encoding in C#.您需要在 C# 中使用 UTF-8 编码。 Export base64 by this command
通过此命令导出 base64
Convert.ToBase64String(Encoding.UTF8.GetBytes("Sample text"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.