问题描述
如果我想产生的Base64-CN codeD输出,我会怎么做,在.NET?
If I want to produce a Base64-encoded output, how would I do that in .NET?
我知道,因为.NET 2.0,还有就是ICryptoTransform接口,以及ToBase64Transform()和FromBase64Transform()该接口的实现。
I know that since .NET 2.0, there is the ICryptoTransform interface, and theToBase64Transform() and FromBase64Transform() implementations of that interface.
但是,这些类被嵌入到System.Security命名空间,并要求使用一个TransformBlock,TransformFinalBlock的,等等。
But those classes are embedded into the System.Security namespace, and require the use of a TransformBlock, TransformFinalBlock, and so on.
有没有更简单的方法为Base64 EN数据的.NET codeA流?
Is there an easier way to base64 encode a stream of data in .NET?
推荐答案
如果你想有一个流转换为Base64的,你可以把一个 ToBase64Transform
到<$c$c>CryptoStream$c$c>:
If you want a stream that converts to Base64, you can put a ToBase64Transform
into a CryptoStream
:
new CryptoStream(stream, new ToBase64Transform(), CryptoStreamMode.Write)
如果你只是想将一个单字节数组为Base64,你可以简单地叫<$c$c>Convert.ToBase64String(bytes)$c$c>.
If you just want to convert a single byte array to Base64, you can simply call Convert.ToBase64String(bytes)
.
在这两种情况下,你可以替换的单词到
与在
。
In both cases, you can replace the word To
with From
.
这篇关于是否有Base64Stream的.NET?哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!