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 '=='
I then convert my string from Base 64 to a byte array like so:
byte[] decodedFromBase64 = Convert.FromBase64String(myText);
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.
Edit: 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:


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().