c# – 字符串长度不能为零.参数名称:oldValue
发布时间:2020-12-15 08:10:19 所属栏目:百科 来源:网络整理
导读:我正在使用Decrypt密码,我坚持这个错误: String cannot be of zero length. Parameter name: oldValue 请帮助解决此错误或建议我另一个解密程序. 这是完整的代码: string decryptpwd = string.Empty;UTF8Encoding encodepwd = new UTF8Encoding();Decoder
我正在使用Decrypt密码,我坚持这个错误:
请帮助解决此错误或建议我另一个解密程序. 这是完整的代码: 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,todecode_byte.Length); char[] decode_char = new char[charcount]; Decode.GetChars(todecode_byte,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,您需要一个基本为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字符串不是加密技术,你不应该用它来加密密码(它们根本不加密) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |