How do I ASCII armor a memory stream? ASCII armoring is the process of encoding a binary data to a printable ASCII string. This is used for example in encryption.
Is there any standard way to do this, also with decoding support, in C#? Like an API? Otherwise, how can it be done?
You should almost always use Base64 (or hex) to represent arbitrary binary data in printable text:
You can use
MemoryStream.ToArray()to convert all the data in aMemoryStreaminto a byte array. Doing this in a streaming fashion would take slightly more work, but would be feasible – and there’s support for it in the framework using theToBase64TransformandFromBase64Transformclasses, which you can use to chain a stream with aCryptoStream. The result will be an ASCII-encoded base64 stream.