A string cannot have zero length. Parameter Name: oldValue

I am working on password decryption and I am stuck with this error:

A string cannot be zero length. Parameter Name: oldValue

Please help with this error or offer me another program for decryption.

Here is the complete code:

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; 
+7
source share
3 answers
 encryptpwd.Replace("","+") 

What exactly are you replacing? You did not specify an initial value which needs to be replaced.

String.Replace takes two string arguments oldValue and newValue . You specified newValue + , however an empty string is not legal for oldValue .

Therefore, if you want to replace the empty space with + try:

 encryptpwd.Replace(" ","+"); 

Or vice versa:

 encryptpwd.Replace("+"," "); 

http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx

+5
source

You ask the Replace method to change an empty string (first parameter) with a plus sign (second parameter). That doesn't make sense, and Replace complains about it.
I think you want to do the reverse

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

Part of this, I'm not sure what the result will be when you change something into the input string and apply FromBase64String to the result. Well, it really depends on what was originally in the string, but for sure (if encryptpwd is really a Base64 string), there are no spaces to replace.

Keep in mind that you cannot pass a normal string to Convert.FromBase64String, you need a string that is the base of the 64 string

What is base line 64

for example

 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); 

The last word. Someone (@Slacks) already tells you that the base64 string is not an encryption technology, and you should not use it to encrypt passwords (they are not encrypted at all)

+5
source

the problem is here

 encryptpwd.Replace("","+") 

Must have a character or string to replace

 encryptpwd.Replace(" ","+") 
+2
source

All Articles