.NET 有 Base64Stream 吗? [英] Is there a Base64Stream for .NET?

查看:23
本文介绍了.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 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆