code_junkie

C# to PHP base64 encode/decode

Nov 12th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. byte[] encbuff = System.Text.Encoding.UTF8.GetBytes("the string");
  2. String enc = Convert.ToBase64String(encbuff);
  3.  
  4. $data = $_REQUEST['in'];
  5. $raw = base64_decode($data);
  6.  
  7. byte[] encbuff = System.Text.Encoding.UTF8.GetBytes("the string");
  8. string enc = Convert.ToBase64String(encbuff);
  9. string urlenc = Server.UrlEncode(enc);
  10.  
  11. $data = $_REQUEST['in'];
  12. $decdata = urldecode($data);
  13. $raw = base64_decode($decdata);
  14.  
  15. byte[] bytes = new byte[1000];
  16. Console.WriteLine(Convert.ToBase64String(bytes));
  17.  
  18. this is a <B>long</b>string. and lets make this a3214 ad0-3214 0czcx 909340 zxci 0324#$@#$%%13244513123
  19.  
  20. dGhpcyBpcyBhIDxCPmxvbmc8L2I+c3RyaW5nLiBhbmQgbGV0cyBtYWtlIHRoaXMgYTMyMTQgYWQwLTMyMTQgMGN6Y3ggOTA5MzQwIHp4Y2kgMDMyNCMkQCMkJSUxMzI0NDUxMzEyMw==
  21.  
  22. private string HTTPPost(string URL, Dictionary<string, string> FormData)
  23. {
  24.  
  25. UTF8Encoding UTF8encoding = new UTF8Encoding();
  26. string postData = "";
  27.  
  28. foreach (KeyValuePair<String, String> entry in FormData)
  29. {
  30. postData += entry.Key + "=" + entry.Value + "&";
  31. }
  32.  
  33. postData = postData.Remove(postData.Length - 1);
  34.  
  35. //urlencode replace (+) with (%2B) so it will not be changed to space ( )
  36. postData = postData.Replace("+", "%2B");
  37.  
  38. byte[] data = UTF8encoding.GetBytes(postData);
  39.  
  40. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
  41.  
  42. request.Method = "POST";
  43. request.ContentType = "application/x-www-form-urlencoded";
  44. request.ContentLength = data.Length;
  45.  
  46. Stream strm = request.GetRequestStream();
  47. // Send the data.
  48. strm.Write(data, 0, data.Length);
  49. strm.Close();
  50.  
  51. WebResponse rsp = null;
  52. // Send the data to the webserver
  53. rsp = request.GetResponse();
  54.  
  55. StreamReader rspStream = new StreamReader(rsp.GetResponseStream());
  56. string response = rspStream.ReadToEnd();
  57.  
  58. return response;
  59.  
  60. }
Add Comment
Please, Sign In to add comment