i am using Encoding and decoding :
For Encoding:
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;
}
编码和解码:
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;
}
我正在发送ServerName:
DEV-SQL1\SQL2008
它被编码为:REVWLVNRTDFcU1FMMjAwOA==
我想再次解码,但是出现了异常,在以下行中:byte[] to_DecodeByte = Convert.FromBase64String(Servername);
异常是:`The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters.`
如何解决这个问题。
请帮助我。