Libsodium "Call to undefined function sodium_randombytes_buf" [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Trying to follow the examples here, but it gives me
Fatal error: Uncaught Error: Call to undefined function sodium_randombytes_buf()
On top of that, the key pairs seems to be generating weird strings like:
kÿòjƒFDú{î—4]F◊î¸˜ßˆu…®_•A∞+.
Is that normal?
Here's my code
<?php
// send
$message = 'Hi, this is Alice';
$alice_to_bob_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey(
file_get_contents('./keys/sec-user-1_box_key.txt'),
file_get_contents('./keys/pub-user-2_box_key.txt')
);
$nonce = sodium_randombytes_buf(SODIUM_CRYPTO_BOX_NONCEBYTES);
$ciphertext = sodium_crypto_box(
$message,
$nonce,
$alice_to_bob_kp
);
// receive
$bob_to_alice_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey(
// $bob_box_secretkey,
// $alice_box_publickey
file_get_contents('./keys/sec-user-2_box_key.txt'),
file_get_contents('./keys/pub-user-1_box_key.txt')
);
$nonce = sodium_randombytes_buf(SODIUM_CRYPTO_BOX_NONCEBYTES);
$plaintext = sodium_crypto_box_open(
$ciphertext,
$nonce,
$bob_to_alice_kp
);
if ($plaintext === false) {
die("Malformed message or invalid MAC");
}
die($plaintext);

There is no such function as sodium_randombytes_buf() the code in the example uses \Sodium\randombytes_buf().
Edit:
From the bug history:
"The sodium_randombytes_* symbols have been removed a while back, as PHP now provide similar functions without this extension"
Bug #74896 sodium's .h defines some functions without .c implementation

Related

syntax error, unexpected T_DOUBLE_ARROW inside class method [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Have been stuck with this little issue, when using key value arrays inside a class |I will get an error syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ']'
class hello{
public function name(){
$allnames = array("name"=>"mark" , "role" => "admin");
}
}
I have checked your code in my system there is no any error in your code
<?php
class hello{
public function name(){
$allnames = array("name"=>"mark" , "role" => "admin");
return $allnames;
}
}
$obj = new hello;
print_r($obj->name())
?>
Please check
You may try assign array as
$allnames = ["name"=>"mark" , "role" => "admin"];

bad request 400 error in amazon api access

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 days ago.
Improve this question
edited code
foreach($parsed_xml->OperationRequest->Errors->Error as $error){
echo "Error code: " . $error->Code . "\r\n";
echo $error->Message . "\r\n"; echo "\r\n";
}
}
function printSearchResults($parsed_xml, $SearchIndex){
print("<table>");
if($numOfItems>0){
foreach($parsed_xml->Items->Item as $current){
print("<td><font size='-1'><b>".$current->ItemAttributes->Title."</b>");
if (isset($current->ItemAttributes->Title)) {
print("<br>Title: ".$current->ItemAttributes->Title);
} elseif(isset($current->ItemAttributes->Author)) {
print("<br>Author: ".$current->ItemAttributes->Author);
} elseif(isset($current->Offers->Offer->Price->FormattedPrice)){
print("<br>Price:".$current->Offers->Offer->Price->FormattedPrice);
}else{
print("<center>No matches found.</center>");
}
}
}
}
if (!isset($params["Timestamp"])) {
$params["Timestamp"] = gmdate('Y-m-d\TH:i:s\Z');
}
ksort($params);
$pairs = array();
foreach ($params as $key => $value) {
array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
}
$canonical_query_string = join("&", $pairs);
$string_to_sign = "GET\n".$endpoint."\n".$uri."\n".$canonical_query_string;
$signature = base64_encode(hash_hmac("sha256", $string_to_sign, $aws_secret_key, true));
$request_url = 'http://'.$endpoint.$uri.'?'.$canonical_query_string.'&Signature='.rawurlencode( $signature);
echo "Signed URL: \"".$request_url."\"";
}
function fetchDataUsingAPI($UniqueBatchId) {
echo $this->firstpageurl;
if( isset($_POST['datafetchresume'])){
$lastbatchdetails = GetTaskLastBatchDetails($_GET['taskid']);
$UniqueBatchId = $lastbatchdetails[0];
$this->firstpageurl = $lastbatchdetails[1];
}else {
$this->firstpageurl = $this->ItemSearch($categorySplit[1],$UniqueBatchId);
}
SaveTaskLastBatchDetails($_GET['taskid'], $UniqueBatchId, $this- >firstpageurl);
return $UniqueBatchId;
Every request needs a signature to be calculated and added to the URL. Check out my PHP function for adding a signature.
Also, use CURL rather than file_get_contents. Even though the API returned a 400 error, it also returned XML with it. That XML probably contains helpful error message. If you use CURL, you can detect the 400 error and still read the contents of the page that was returned. With file_get_contents, a 400 error just returns an error. (My recollection of that may be off, but you'll like CURL better.)
Check here for more info on Amazon API error code
In the PHP code, there are three variables left undefined by me. MY_ASSOCIATE_ID, MY_PUBLIC_KEY, MY_PRIVATE_KEY must be defined by you with appropriate values. The two keys are given to you by amazon. You can, for a while, get them here:
https://portal.aws.amazon.com/gp/aws/securityCredentials
Or check the "My Account" menu at the top of this page and go hunting for your security credentials. The "new and improved" system has been reported to not work with this API, so I would get your two keys from the link above while you still can. Store them in a safe place.
The associate ID can be anything--the API doesn't check it. The API uses uses your URL parameters to generate a signature with your public key, which is included in the URL, and the secret key they have on file associated with the public key you provided. The signature you provide in the URL must match theirs exactly, so your keys and your sig function must exactly match theirs.

My codes are not working (json, arrays) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
$wiki_img = "http://en.wikipedia.org/w/api.php?action=query&titles=Google&prop=pageimages&format=json&pithumbsize=500";
$json2 = file_get_contents($wiki_img);
$data2 = json_decode($json2, TRUE);
foreach ($data2['query']['pages'] as $pages)
{
print_r($pages['source']);
}
My codes are not working.
But I can't find what is error.
I got this error
"Notice: Undefined index: source in C:\xampp\htdocs\"
As your JSON data which you got is
{
query: {
pages: {
1092923: {
pageid: 1092923,
ns: 0,
title: "Google",
thumbnail: {
source: "http://upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Googleplex-Patio-Aug-2014.JPG/500px-Googleplex-Patio-Aug-2014.JPG",
width: 500,
height: 375
},
pageimage: "Googleplex-Patio-Aug-2014.JPG"
}
}
}
}
It should be..
foreach($data2['query']['pages'] as $value){
echo $value['thumbnail']['source'];
}
Output:
http://upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Googleplex-Patio-Aug-2014.JPG/500px-Googleplex-Patio-Aug-2014.JPG

PHP Parse error: syntax error, unexpected ':' line 7 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Please i dont know how to remove this error on line 7 onto this $rest_url = “https://mydomain.com/rest-api/analytics/HTML/”.$login.”/”.$hash.”/”.$timestamp.”.do”;
$timestamp = round(microtime(true) * 1000);
$login = ‘username’;
$password = ‘password’;
$hash = md5(md5($password).$timestamp);
$rest_url = “https://mydomain.com/rest-api/analytics/HTML/”.$login.”/”.$hash.”/”.$timestamp.”.do”;
$post_data = array(
‘range’ => ‘LAST_7_DAYS’,
‘groupBy’ => ‘PLACEMENT’
);
/* Options of HTTP request; http key should be used when posting to https url */
$options = array(
‘http’ => array(
‘header’ => “Content-type: application/x-www-form-urlencoded\r\n”,
‘method’ => ‘POST’,
‘content’ => http_build_query($post_data)
)
);
/* Actual call to REST URL */
$context = stream_context_create($options);
$result = file_get_contents($rest_url, false, $context);
echo($result);
Your string starting and ending characters are incorrect.
You are using ‘ and “ ... replace them with ' and " to make your code valid.
since file_get_contents() is not reliable in remote connections,
You have to use CURL to overcome this http error.
For more info on curl_init read this

PHP: Catchable fatal error: Object of class stdClass could not be converted to string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I get the following dump & error when running the attached code. What I'm confused by is that $procID appears to be returned as a string, but as soon as I attempt to pass it again, its an object? How do I get it to be/stay a string? Thanks.
object(stdClass)#2 (1) {
["processId"]=> string(13)
"Genesis114001" } string(311)
"Genesis114001" string(293) " Genesis
" Catchable fatal error: Object of
class stdClass could not be converted
to string in
C:\wamp\www\SugarCE\testSOAPShawn.php
on line 15
<?php
set_time_limit(0);
require_once('nusoap.php');
require_once('BenefitSOAP.php'); //WSDL to PHP Classes
$client = new SoapClient('C:\wsdl\BenefitDeterminationProcess_BenefitDialogueServiceSOAP.wsdl', array('trace' => 1));
$procID = $client->start(array("prefix"=>"Genesis"));
$respXML = $client->__getLastResponse();
$requXML = $client->__getLastRequest();
echo "<p/>";
var_dump($procID);
//echo "<p/>";
var_dump($respXML);
//echo "<p/>";
var_dump($requXML);
$exchange = $client->exchangeOptions(array("processId"=>$procID)); //LINE 15
$end = $client->stop(array("processId"=>$procID));
?>
Whatever the $client->start() method is returning, it is typed as an object. You can access the properties of the object using the -> operator:
$procID = $client->start(array("prefix"=>"Genesis"));
...
$exchange = $client->exchangeOptions(array("processId"=>$procID->processId));
This was probably an array, but is getting typed into an object. Thus, you end up with the stdClass.
Another (and possibly better) way to do this is to type the return. That way, you don't have to make a new array for later passing as argument:
$procID = (array) $client->start(array("prefix"=>"Genesis"));
...
$exchange = $client->exchangeOptions($procID);
$end = $client->stop($procID);

Categories