Search code examples
hashbittorrenturl-parameters

The torrent info_hash parameter


How does one calculate the info_hash parameter? Aka the hash corresponding to the info dictionar??

From official specs:

info_hash The 20 byte sha1 hash of the bencoded form of the info value from the metainfo file. Note that this is a substring of the metainfo file. This value will almost certainly have to be escaped.

Does this mean simply get the substring from the meta-info file and do a sha-1 hash on the reprezentative bytes??

.... because this is how i tried 12 times but without succes meaning I have compared the resulting hash with the one i should end up with..and they differ ..that + tracker response is FAILURE, unknown torrent ...or something

So how do you calculate the info_hash?


Solution

  • bdecode the metafile. Then it's simply sha1(bencode(metadata['info'])) (i.e. bencode only the info dict again, then hash that).