Is there a Base64Stream for .NET?(.NET 有 Base64Stream 吗?)
问题描述
如果我想生成 Base64 编码的输出,我将如何在 .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 the ToBase64Transform() 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.
有没有更简单的方法在 .NET 中对数据流进行 base64 编码?
Is there an easier way to base64 encode a stream of data in .NET?
推荐答案
如果你想要一个转换成 Base64 的流,你可以把一个 ToBase64Transform
放到一个 CryptoStream
:
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,您只需调用 Convert.ToBase64String(bytes)
.
If you just want to convert a single byte array to Base64, you can simply call Convert.ToBase64String(bytes)
.
在这两种情况下,您都可以将单词 To
替换为 From
.
In both cases, you can replace the word To
with From
.
这篇关于.NET 有 Base64Stream 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.NET 有 Base64Stream 吗?


- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01