title: Encode and Decode in c# asp.net?
body: <p>i am using Encoding and decoding :</p>
  
  <p>For Encoding:</p>
  
  <pre><code>private string EncodeServerName(string ServerName)
      {
        byte[] NameEncodein = new byte[ServerName.Length];
        NameEncodein = System.Text.Encoding.UTF8.GetBytes(ServerName);
        string EcodedName = Convert.ToBase64String(NameEncodein);
        return EcodedName;
      }
  </code></pre>
  
  <p>and Decoding:</p>
  
  <pre><code>     public string DecoAndGetServerName(string Servername)
       {
           System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
           System.Text.Decoder strDecoder = encoder.GetDecoder();
           byte[] to_DecodeByte = Convert.FromBase64String(Servername);
           int charCount = strDecoder.GetCharCount(to_DecodeByte, 0, to_DecodeByte.Length);
           char[] decoded_char = new char[charCount];
           strDecoder.GetChars(to_DecodeByte, 0, to_DecodeByte.Length, decoded_char,0);
           string Name = new string(decoded_char);
  
           return Name;
       }
  </code></pre>
  
  <p>I am sending ServerName:<code>DEV-SQL1\SQL2008</code></p>
  
  <p>It is encoded:<code>REVWLVNRTDFcU1FMMjAwOA==</code></p>
  
  <p>Again i want to decode but getting Exception:in line:</p>
  
  <p><code>byte[] to_DecodeByte = Convert.FromBase64String(Servername);</code></p>
  
  <p>Exception IS:</p>
  
  <p>`The input is not a valid Base-64 string as it contains a non-base 64 character, </p>
  
  <p>more than two padding characters, or a non-white space character among the padding characters.`</p>
  
  <p>How to solve this issue.</p>
  
  <p>Please Help Me</p>