【发布时间】:2012-08-29 12:56:24
【问题描述】:
我有一个byte[],我正在寻找对它进行 base64 编码的最有效方法。
问题在于,内置的.Net 方法Convert.FromBase64CharArray 需要char[] 作为输入,而将我的byte[] 转换为char[] 只是为了再次将其转换为base64 编码数组似乎很愚蠢。
有没有更直接的方法?
[[EDIT:]] 我将解释我想要更好地实现的目标 - 我有一个 byte[],我需要返回一个新的 base64 编码 byte[]
【问题讨论】:
-
你的字节数组是什么编码的? ascii、utf8 等?
-
您写的是要转换为 base64 而不是“FromBase64”
-
也许我遗漏了什么......但你不能使用
string Convert.ToBase64String(byte[])和byte[] Convert.FromBase64String(string)吗? -
@SimonWhitehead 我已经更新了我的问题,以澄清为什么这还不够好
-
将字符串转换为字节是另一回事。使用 byte[] Encoding.ASCII.GetBytes(theBase64String)