The torrent info_hash parameter

此生再无相见时 提交于 2019-12-04 11:37:08
pyroscope

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

Peter Quiring

The metafile is already bencoded so I don't understand why you encode it again?

I finally got this working in Java code, here is my code:

byte metaData[];  //the raw .torrent file

int infoIdx = ?;  //index of 'd' right after the "4:info" string

info_hash = SHAsum(Arrays.copyOfRange(metaData, infoIdx, metaData.length-1));

This assumes the 'info' block is the last block in the torrent file (wrong?)

Don't sort or anything like that, just use a substring of the raw torrent file.

Works for me.

Visit https://gist.github.com/shxsun/9085646 , this is a python code, explains how info_generate, good luck.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!