gpt4 book ai didi

c# - 字符串长度不能为零。参数名称 : oldValue

转载 作者:太空狗 更新时间:2023-10-29 17:36:51 26 4
gpt4 key购买 nike

我正在解密密码,但遇到了这个错误:

String cannot be of zero length. Parameter name: oldValue

请帮助解决这个错误或建议我另一个解密程序。

完整代码如下:

string decryptpwd = string.Empty;
UTF8Encoding encodepwd = new UTF8Encoding();
Decoder Decode = encodepwd.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(encryptpwd.Replace("+",""));
int charcount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decode_char = new char[charcount];
Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decode_char, 0);
decryptpwd = new String(decode_char);
return decryptpwd;

最佳答案

您要求 Replace 方法将空字符串(第一个参数)更改为加号(第二个参数)。这没有任何意义,Replace 对此有提示。
我想你想做相反的事情

 byte[] todecode_byte = Convert.FromBase64String(encryptpwd.Replace("+",""));

我不确定当您将某些内容更改为输入字符串并将 FromBase64String 应用于结果时,结果会是什么。好吧,这实际上取决于字符串中的原始内容,但可以肯定的是(如果 encryptpwd 确实是一个 Base64 字符串)没有空格可以替换。

请记住,您不能将普通字符串传递给 Convert.FromBase64String,您需要一个 base 64 字符串

What is a base 64 string

例如

string pwd = "786";   // The original string

UnicodeEncoding u = new UnicodeEncoding();
byte[] x = u.GetBytes(pwd); // The Unicode bytes of the string above

// Convert bytes to a base64 string
string b64 = Convert.ToBase64String(x);
Console.WriteLine(b64);

// Go back to the plain text string
byte[] b = Convert.FromBase64String(b64);
string result = u.GetString(b);
Console.WriteLine(result);

最后一句话。有人 (@Slacks) 已经告诉你 base64 字符串不是加密技术,你不应该用它来加密密码(它们根本没有加密)

关于c# - 字符串长度不能为零。参数名称 : oldValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16733845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com