I converting a swf project to php, I’m not good with actionscript much so I need help to convert functions Hex.toArray, Hex.fromString, Base64.encodeByteArray in actionscript3 to php.
ActionScript
public function spawn(query_str:String, key:String, token:String = "") : String{
var tmp1:* = key + "&" + token;
var tmp2:* = Crypto.getHMAC("sha1");
var tmp3:* = Hex.toArray(Hex.fromString(tmp1));
var tmp4:* = Hex.toArray(Hex.fromString(query_str));
var tmp5:* = tmp2.compute(tmp3, tmp4);
return Base64.encodeByteArray(tmp5);
}
This is PHP function I converted, but results of two functions are different
function spawn($query_str, $key, $token = ''){
$tmp1 = $key . "&" . $token;
$tmp3 = pack("H*" , bin2hex($tmp1));
$tmp4 = pack("H*" , bin2hex($query_str));
$tmp5 = hash_hmac('sha1', $tmp4, $tmp3);
return base64_encode($tmp5);
}
You can use
bin2hexin PHP, andpack("H*", ...)in lieu ofhex2bin. The primarily used base64 functions in PHP arebase64_encodeandbase64_decode.Arrays are seldomly used for data representation; binary data is generally kept in strings in PHP. But if really needed
$array = array_map("ord", str_split($string));would do.