是否有Base64Stream的.NET?哪里? [英] Is there a Base64Stream for .NET? where?

查看:193
本文介绍了是否有Base64Stream的.NET?哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想产生的Base64-CN codeD输出,我会怎么做,在.NET?

If I want to produce a Base64-encoded output, how would I do that in .NET?

我知道,因为.NET 2.0,还有就是<一个href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.icryptotransform.aspx">ICryptoTransform接口,以及 <一href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.tobase64transform.aspx">ToBase64Transform()和<一href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.frombase64transform.aspx">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.

有没有更简单的方法为Base64 EN数据的.NET codeA流?

Is there an easier way to base64 encode a stream of data in .NET?

推荐答案

如果你想有一个流转换为Base64的,你可以把一个 ToBase64Transform 到<一个href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.cryptostream.aspx"><$c$c>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,你可以简单地叫<一href="http://msdn.microsoft.com/en-us/library/system.convert.tobase64string.aspx"><$c$c>Convert.ToBase64String(bytes).

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

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