seansammut Posted November 24, 2009 Share Posted November 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/182720-string128-string439/ Share on other sites More sharing options...
mikesta707 Posted November 24, 2009 Share Posted November 24, 2009 without seeing any code there is not much chance of being able to get answers that aren't more than guesses Quote Link to comment https://forums.phpfreaks.com/topic/182720-string128-string439/#findComment-964399 Share on other sites More sharing options...
seansammut Posted November 24, 2009 Author Share Posted November 24, 2009 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>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182720-string128-string439/#findComment-964401 Share on other sites More sharing options...
seansammut Posted November 24, 2009 Author Share Posted November 24, 2009 What is the difference between these two types of strings (the ones in the subject)? Quote Link to comment https://forums.phpfreaks.com/topic/182720-string128-string439/#findComment-964409 Share on other sites More sharing options...
Alex Posted November 24, 2009 Share Posted November 24, 2009 Their length, apparently. Quote Link to comment https://forums.phpfreaks.com/topic/182720-string128-string439/#findComment-964410 Share on other sites More sharing options...
seansammut Posted November 24, 2009 Author Share Posted November 24, 2009 Can I type cast from str(439) to str(128)? Quote Link to comment https://forums.phpfreaks.com/topic/182720-string128-string439/#findComment-964412 Share on other sites More sharing options...
Alex Posted November 24, 2009 Share Posted November 24, 2009 No, this isn't a data type issue, they're both of type string. Just one is 128 bytes long and the other is 439 bytes long. Quote Link to comment https://forums.phpfreaks.com/topic/182720-string128-string439/#findComment-964413 Share on other sites More sharing options...
seansammut Posted November 24, 2009 Author Share Posted November 24, 2009 Thing is that when I try to decrypt the data using openssl_private_decrypt, the function returns a false and the data does not decrypt. I think the reason for the problem is that the data is in String (439)....... Quote Link to comment https://forums.phpfreaks.com/topic/182720-string128-string439/#findComment-964416 Share on other sites More sharing options...
seansammut Posted November 24, 2009 Author Share Posted November 24, 2009 Any solutions? Quote Link to comment https://forums.phpfreaks.com/topic/182720-string128-string439/#findComment-964697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.