Generate info_hash of torrent for xbtt
-
25-09-2019 - |
Question
I am trying to create my own torrent tracker but dont know how to generate info_hash
that is used xbtt
to track torrents.
Is this possible with php?
I am using this function to bencode and decode http://paste.lisp.org/display/17178
Is this the correct hash?
$nn = file_get_contents('my.torrent');
$file = bdecode($nn);
$hash = sha1( bencode($file[info]) );
Thank You.
Solution
According to the bittorrent specification the info_hash is an urlencoded 20-byte SHA1 hash of the value of the info key from the Metainfo file.
You can calculate the sha1 hash of a string in php using the sha1
function and url encode ot with the urlencode
function.
UPDATE:
Your method is not correct. You need to bdecode the torrent file, which you have already done. But you need to calculate the info_hash based on the value of the info key from the Metainfo (torrent) file. When you have done that, you still need to urlencode the result, which it seems is also missing from your current implementation.