Я пытаюсь имитировать скрипт php, который делает следующее:
- замените все пробелы в GET-переменной каждый знак + ($ var = preg_replace ("/ \ s /", "+", $ _ GET ['var']);)
- декодирование в base64: base64_decode ($ var);
1-й я добавил метод, выполняющий декодирование base64:
public string base64Decode(string data)
{
try
{
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(data);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
return result;
}
catch (Exception e)
{
throw new Exception("Error in base64Decode" + e.Message);
}
}
но кажется, что UTF-8 не выполняет эту работу, поэтому я попробовал тот же метод, но с UTF-7
public string base64Decode(string data)
{
try
{
System.Text.UTF7Encoding encoder = new System.Text.UTF7Encoding();
System.Text.Decoder utf7Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(data);
int charCount = utf7Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf7Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
return result;
}
catch (Exception e)
{
throw new Exception("Error in base64Decode" + e.Message);
}
}
И последнее, что нужно сказать: успешное декодирование php содержит специальные знаки, такие как зарегистрированный знак и знак товарного знака, но версия C # этого не делает!
также влияет ли язык php base64_decode на язык сервера?