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 吗?
基础教程推荐
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
