Jump to content

String(128) & String(439) ?!?!


seansammut

Recommended Posts

Hi,

 

I created a very simple API and when a request is invoked to the API, a public key is sent and the API encrypts the message using the public key and sends the data back. My problem is that when I use var_dump, the data received is String(439), when it is supposed to be String(128) in order to be able to decrypt the message using opensll.

 

Any ideas how to solve this problem...

 

Thanks

Link to comment
Share on other sites

This is the one which makes the requests:

 

<?php

$res=openssl_pkey_new();

openssl_pkey_export($res, $privatekey);


$publickey=openssl_pkey_get_details($res);
$publickey=$publickey["key"];

$query_vals = array ('method' => 'getImage', 'public_key' => $publickey);

$request = '';
foreach($query_vals as $key => $value) {
    $request .= $key.'='.urlencode($value).'&';
}

$request = rtrim($request, '&');


$ch = curl_init("http://apihost/APImanage.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
curl_close ($ch);



var_dump ($response);

/*$bool = openssl_private_decrypt($response,$result,$privatekey);
//var_dump($bool);

echo "$response";
echo "$result";*/

?>

 

This handles the requests:

 

<?php

function encryption($data)
{
   openssl_public_encrypt($data,$crypttext,$_POST['public_key']);
   return $crypttext;
}

require_once('manage.php');

$m = new manage();
    
switch ($_POST['method'])
  {	  
    case "getImage": 
		   $result = encryption($m->getImage());		  
   		   echo $result;		  		   
	  break;
	case "getLink":
	  $result = encryption($m->getLink());
	  echo "$result";
	  break;		  
}
?>

 

This returns the data requested by the above script:

 

<?php
class manage {

    function __construct() {	 
    }

    function getImage() {
        return '<img src="http://www.daveramsey.com/media/image/general/pic-car1.jpg"/>'; 
    }

function getLink()
{
  return '<a href="http://www.w3schools.com/">Visit W3Schools!</a>';
}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.