void background_DoWork(object sender, DoWorkEventArgs e) { // Get the RSA public key that we will use string cert = http.Post(address, "getkey=y"); rsa.LoadCertificateFromString(cert); // Generate the AES keys, encrypt them with the RSA public key, then send them to the PHP script. aes.GenerateRandomKeys(); string key = Utility.ToUrlSafeBase64(rsa.Encrypt(aes.EncryptionKey)); string iv = Utility.ToUrlSafeBase64(rsa.Encrypt(aes.EncryptionIV)); string result = http.Post(address, "key=" + key + "&iv=" + iv); // If the PHP script sends this message back, then the connection is now good. connected = (result == "AES OK"); }
void background_DoWork(object sender, DoWorkEventArgs e) { try { error = false; switch ((RequestOption)e.Argument) { case RequestOption.Get: response = http.Get(request.url, request.settings); break; case RequestOption.Post: response = http.Post(request.url, request.data, request.settings); break; } } catch (Exception ex) { error = true; response = "Error getting HTTP request: " + ex.Message; } }