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
https://forums.phpfreaks.com/topic/182720-string128-string439/
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
https://forums.phpfreaks.com/topic/182720-string128-string439/#findComment-964401
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.