Base-64 char数组错误的长度无效 [英] Invalid length for a Base-64 char array error

查看:68
本文介绍了Base-64 char数组错误的长度无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.Text.UTF8Encoding编码器=新的System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte [] todecode_byte = Convert.FromBase64String(DTourPrNo); -----> 这里我遇到了错误.

int charCount = utf8Decode.GetCharCount(todecode_byte,0,todecode_byte.Length);
char [] encode_char =新的char [charCount]; utf8Decode.GetChars(todecode_byte,0,todecode_byte.Length,decoded_char,0);
字符串结果=新的String(decoded_char);返回结果;

System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(DTourPrNo);----->here i am getting error.

int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char); return result;

推荐答案

DTourPrNo的内容未正确地以64位编码.它应该使用类似这样的东西来生产:

The contents of DTourPrNo isn''t properly base 64 encoded. It should be produced using something like this:

string DTourPrNo = Convert.ToBase64String(System.Text.UnicodeEncoding.Unicode.GetBytes("string content"));


嗨..,

我认为您没有将正确的编码字符串传递给方法
FromBase64String

这里是用一个例子来解释...

假设原始字符串是 rajesh
如果使用base64对其进行编码,则会得到 cmFqZXNoDQo =

如果解码编码的字符串,您将得到像这样的原始字符串....

hi ..,

i think you are not passing the correct encoding string to the method
FromBase64String

here am explaining with an example...

let say the original string is rajesh
if you encode it using base64 you will get cmFqZXNoDQo=

if decode the encoded sting you will get original string like this ....

<pre lang="vb">? Convert.FromBase64String("cmFqZXNoDQo=")
{byte[8]}
    [0]: 114
    [1]: 97
    [2]: 106
    [3]: 101
    [4]: 115
    [5]: 104
    [6]: 13
    [7]: 10



谢谢
拉杰什B



Thanks
Rajesh B


这篇关于Base-64 char数组错误的长度无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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