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”的类似函数?我只能做到以下几点。AS到PHP(decodeToByteArray,encodeByteArray)
key = base64_decode(key);
$message = $this_id ."-".$timestamp;
$message = hash_hmac ('sha1', $key , $message) . $message;
$gen_token = base64_encode(key);
做了一些动作的快速搜索显示,有一些是从库[twitterscript](http://code.google.com/p/twitterscript/source/browse/trunk/src/ com/dynamicflash/util/Base64.as?r = 12)。 – Qix
另外,OP,也许你可以问一个更具体的问题,而不是要求我们为你翻译代码? – Qix
为什么用'this_id +' - '+ timestamp'覆盖'message'?这没有任何意义。 –