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

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

问题描述

大家好,

当我尝试解密存储在DB2中的binary(16),null数据类型中的密码时,它给我类似``Base-64 char数组的无效长度''之类的错误.

我尝试从asp.net论坛之一尝试以下代码.

Hi all,

When i try to decrypt my password which is stored in binary(16),null datatype in DB, it gives me error like ''Invalid length for a Base-64 char array.''.

i try the below code from one of the asp.net forum.

public string DecryptPassowrd(object obj)
{
    string password = obj.ToString();
    System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
    System.Text.Decoder utf8Decode = encoder.GetDecoder();
    byte[] todecode_byte = Convert.FromBase64String(password);
    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;
}



我在 byte[] todecode_byte = Convert.FromBase64String(password);行出现了错误.

当我用Google搜索该错误时,许多网站都说将"替换为"+".但是当我这样做时,它给了我另一个错误.

字符串的长度不能为零.
参数名称:oldValue

我正在尝试解码"0xA02B92F62E209BC4058E08CF4F6C9689".

那我该怎么做才能克服这个错误呢?

谢谢,
krunal



I got the error at byte[] todecode_byte = Convert.FromBase64String(password); line.

when i googled for that error many of site says to replace " " to "+". but when i did this it gives me another error.

String cannot be of zero length.
Parameter name: oldValue

i am trying to decode "0xA02B92F62E209BC4058E08CF4F6C9689".

so what sould i do to overcome this error?

thanks,
krunal

推荐答案

那看起来不像base64字符串-看起来像普通的十六进制数字-尽管有点十六进制数字-而"0x"前缀确实对此也有暗示.

我将回到存储信息的位置,然后查看将其从二进制转换为可以存储在数据库中的格式的过程,然后将其反转.

顺便说一句:您确实意识到Base64并不是一种加密算法,不是吗?并提供与将数据打印在T恤上并在Ebay上出售这些数据相同的安全级别?
That doesn''t look like a base64 string - it looks like a normal hex number - albeit a bit hex number - and the "0x" prefix does sort of hint at that as well.

I would go back to where you stored the information, and look at the process you used to convert it from binary to a format you can store in a DB - then reverse it.

BTW: You do realize that Base64 is not an encryption algorithm in nay way, don''t you? And that it provides the same security level as printing your data on a T shirt and selling them on Ebay?


尝试一下,这样会起作用

公共字符串Decryptdata(string cryptopwd)
{
字符串解密pwd = string.Empty;
UTF8Encoding encodepwd =新的UTF8Encoding();
解码器解码= encodepwd.GetDecoder();
byte [] todecode_byte = Convert.FromBase64String(encryptpwd);
int charCount = Decode.GetCharCount(todecode_byte,0,todecode_byte.Length);
char [] encode_char =新的char [charCount];
Decode.GetChars(todecode_byte,0,todecode_byte.Length,decoded_char,0);
cryptopwd =新的String(decoded_char);
返回cryptopwd;
}
try this it will work

public string Decryptdata(string encryptpwd)
{
string decryptpwd = string.Empty;
UTF8Encoding encodepwd = new UTF8Encoding();
Decoder Decode = encodepwd.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
decryptpwd = new String(decoded_char);
return decryptpwd;
}


在"之间添加空格

"应该是"
add an space between ""

"" should be " "


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

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