如何去codeA文本从Base64的字节数组的字符串,得到这个字节数组的字符串属性数据不会遭到损坏 [英] How to decode a string of text from a Base64 to a byte array, and the get the string property of this byte array without data corruption

查看:302
本文介绍了如何去codeA文本从Base64的字节数组的字符串,得到这个字节数组的字符串属性数据不会遭到损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我有一个文本字符串,连接$ C $光盘基地64象下面这样:

Ok so I have a string of text, encoded in Base 64 like below:

string myText = "abcBASE64TEXTGOESHEREdef==";  // actual string is 381 characters long with trailing '=='

然后,我将我的字符串从基地64字节数组,像这样:

I then convert my string from Base 64 to a byte array like so:

byte[] decodedFromBase64 = Convert.FromBase64String(myText);

在这一点上,我想获得这个字节数组的字符串值,并保存在一个文本文件中的无数据丢失或损坏。下面的code似乎并没有那样做:

At this point, I want to get the string value of this byte array and save this in a text file without data loss or corruption. The code below doesn't seem to be doing it:

string myDecodedText = Encoding.ASCII.GetString(decodedFromBase64);
StreamWriter myStreamWriter = new StreamWriter("C:\\OpenSSL-Win32\\bin\\textToDecrypt.txt");
myStreamWriter.Write(myString);
myStreamWriter.Flush();
myStreamWriter.Close();

有人可以告诉我,我要去哪里错了。

Can somebody please tell me where I'm going wrong.

编辑:输出是不可读的,我需要去codeD字符串,然后使用OpenSSL解密。输出和从OpenSSL的结果均为如下:

The output is unreadable, I need to take the decoded string and then use OpenSSL to decrypt it. The Output and the result from OpenSSL are both below:

推荐答案

如果字符串为EN codeD,然后内容看起来很像你在你的文本文件。但是,为了确保该文件没有得到损坏,你应该写文件内容为二进制,而不是使用文本连接codeR。请查看 File.WriteAllBytes()

If the string is encoded then the contents would look much like what you have in your text file. But to ensure that the file is not getting corrupt you should write the file content as binary instead of using a text encoder. Check out File.WriteAllBytes().

这篇关于如何去codeA文本从Base64的字节数组的字符串,得到这个字节数组的字符串属性数据不会遭到损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆