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);
我不知道 AS 但我需要将上面的 AS 函数转换为 PHP。php中是否有类似“decodeToByteArray”和“encodeByteArray”的类似函数?我只能做到以下几点。
key = base64_decode(key);
$message = $this_id ."-".$timestamp;
$message = hash_hmac ('sha1', $key , $message) . $message;
$gen_token = base64_encode(key);