.NET 有 Base64Stream 吗?

Is there a Base64Stream for .NET?(.NET 有 Base64Stream 吗?)
本文介绍了.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 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)