如何ASCII 装甲内存流? ASCII 装甲是将二进制数据编码为可打印 ASCII 字符串的过程。例如,这用于加密。
在 C# 中是否有任何标准方法可以做到这一点,并且还支持解码?就像 API 一样?不然的话,怎么办呢?
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?
发布评论
评论(3)
您几乎应该始终使用 Base64 (或十六进制)来表示可打印文本中的任意二进制数据:
您可以使用
MemoryStream.ToArray()
将所有数据转换为一个MemoryStream
转换为字节数组。以流式传输方式执行此操作需要稍微多一些的工作,但这是可行的 - 并且使用ToBase64Transform
和FromBase64Transform
类,您可以使用它来链接具有CryptoStream
的流。结果将是 ASCII 编码的 base64 流。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 aMemoryStream
into 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 theToBase64Transform
andFromBase64Transform
classes, which you can use to chain a stream with aCryptoStream
. The result will be an ASCII-encoded base64 stream.您可以使用 base64 编码来获取二进制数据的相当紧凑的 ASCII 表示形式:
使用
Convert.FromBase64String
方法对字符串进行解码。You can use base64 encoding to get a reasonably compact ASCII representation of binary data:
Use the
Convert.FromBase64String
method to decode the string.检查我对密码做了什么,使用 Convert.FromBase64String< /a> 和 Convert.ToBase64String 方法
//编码
//解码
Check this what have i done for my password, using Convert.FromBase64String and Convert.ToBase64String Methods
//encode
//decode