JMK*_*JMK 13 .net c# base64 openssl
好吧,我有一串文字,用Base 64编码,如下所示:
string myText = "abcBASE64TEXTGOESHEREdef=="; // actual string is 381 characters long with trailing '=='
Run Code Online (Sandbox Code Playgroud)
然后我将我的字符串从Base 64转换为字节数组,如下所示:
byte[] decodedFromBase64 = Convert.FromBase64String(myText);
Run Code Online (Sandbox Code Playgroud)
此时,我想获取此字节数组的字符串值,并将其保存在文本文件中,而不会丢失数据或损坏.下面的代码似乎没有这样做:
string myDecodedText = Encoding.ASCII.GetString(decodedFromBase64);
StreamWriter myStreamWriter = new StreamWriter("C:\\OpenSSL-Win32\\bin\\textToDecrypt.txt");
myStreamWriter.Write(myString);
myStreamWriter.Flush();
myStreamWriter.Close();
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我哪里出错了.
编辑:输出不可读,我需要获取解码后的字符串然后使用OpenSSL解密它.输出和OpenSSL的结果如下:
Hus*_*awi 13
public static string base64Decode(string data)
{
byte[] toDecodeByte = Convert.FromBase64String(data);
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
int charCount = utf8Decode.GetCharCount(toDecodeByte, 0, toDecodeByte.Length);
char[] decodedChar = new char[charCount];
utf8Decode.GetChars(toDecodeByte, 0, toDecodeByte.Length, decodedChar, 0);
string result = new String(decodedChar);
return result;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
44523 次 |
最近记录: |