$value) { $request_headers[] = "$name:$value"; } switch ($method) { case 'GET': //open connection $ch = curl_init(); //set the url, number of GET vars, GET data curl_setopt($ch,CURLOPT_URL, $url .=$_SERVER['REQUEST_URI']); curl_setopt($ch,CURLOPT_GET, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); //execute get $result = ""; //$result = curl_exec($ch); header('Content-Type: '. $contenttype); if(strpos($RequestContentType,'img') !== false){ //image encrypt/decrypt not supported $result = curl_exec($ch); echo $result; } else { //execute get $result = curl_exec($ch); echo @decrypt($result, $iv, $secretKey); } break; case 'POST': //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, $url .=$_SERVER['REQUEST_URI']); curl_setopt($ch,CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers); $json = file_get_contents('php://input'); $jsonenc = @encrypt($json, $iv, $secretKey); curl_setopt($ch,CURLOPT_POSTFIELDS, $jsonenc); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); //execute post $result = curl_exec($ch); header('Content-Type: '. $contenttype); if(strpos($RequestContentType,'img') !== false){ //image encrypt/decrypt not supported echo $result; } else { echo @decrypt($result, $iv, $secretKey); } break; default: //do nothing break; } // //Thanks @Stéphane Moreau // //final String iv = "0123456789123456"; // This has to be 16 characters //final String secretKey = "Replace this by your secret key"; // function encrypt($message, $initialVector, $secretKey) { return base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_128, md5($secretKey), $message, MCRYPT_MODE_CFB, $initialVector ) ); } function decrypt($message, $initialVector, $secretKey) { return mcrypt_decrypt( MCRYPT_RIJNDAEL_128, md5($secretKey), base64_decode($message), MCRYPT_MODE_CFB, $initialVector ); } ?>