简体   繁体   English

C#中的byte [] encodeBase64(byte [] binaryData)等效

[英]byte[] encodeBase64(byte[] binaryData) equvalent in c#

In Java, Apache provides a encoding library namely apache-commons and there is a method that's signiture is 在Java中,Apache提供了一个编码库,即apache-commons,并且有一种方法的签名是

byte[] encodeBase64(byte[] binaryData)

In C#, we try to do the same thing. 在C#中,我们尝试做同样的事情。 however, we couldn't find any library or method like this. 但是,我们找不到任何这样的库或方法。 How we can encode our byte array to Base64 byte array? 我们如何将字节数组编码为Base64字节数组?

You can leverage the Convert.ToBase64String method. 您可以利用Convert.ToBase64String方法。 This will however not return a byte[] but a string type. 但是,这不会返回byte[]而是string类型。 To get it in bytes, you will have to perform a text encoding. 要以字节为单位获取它,您将必须执行文本编码。

string base64 = Convert.ToBase64String(binaryData);
byte[] base64bytes = System.Text.Encoding.ASCII.GetBytes(base64);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM