AS to PHP (decodeToByteArray, encodeByteArray)

advertisements
message = "this is the message";
key = "the_key";
timestamp = "20130121";
this_id = "13291";

key = Base64.decodeToByteArray(key);
message = this_id + "-" + timestamp;
hmac = Crypto.getHMAC("sha1");
message = Hex.fromArray(hmac.compute(key, Hex.toArray(Hex.fromString(message)))) + "-" + message;
data = Hex.toArray(Hex.fromString(message));
gen_token = Base64.encodeByteArray(data);

I do not know AS but I need to convert the above AS function to PHP. Are there any similar functions in php which is similar to "decodeToByteArray" and "encodeByteArray"? I am only able to do the following.

key = base64_decode(key);
$message = $this_id ."-".$timestamp;
$message = hash_hmac ('sha1', $key , $message) . $message;
$gen_token = base64_encode(key);


string **base64_encode** ( string *$data* )

http://php.net/manual/en/function.base64-encode.php

string **base64_decode** ( string *$data* [, bool *$strict = false* ] )

http://php.net/manual/en/function.base64-decode.php

ByteArray (array of 8-bit entities) is, in effect, a string.

So, base64_encode and base64_decode do all what you need.