如何计算info_hash参数?又名对应于信息字典的哈希??
来自官方规范:
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.
这是否意味着简单地从元信息文件中获取子字符串并对代表字节进行 sha-1 哈希?
...因为我尝试了 12 次但没有成功,这意味着我已将生成的哈希值与我最终应该得到的哈希值进行了比较..并且它们不同..+跟踪器响应是失败,未知 torrent 。 ..或者什么东西
那么如何计算 info_hash 呢?
最佳答案
图元文件已经编码,所以我不明白为什么要再次编码?
我终于在 Java 代码中得到了这个工作,这是我的代码:
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));
这假设“info” block 是 torrent 文件中的最后一个 block (错误?)
不要进行排序或类似的操作,只需使用原始 torrent 文件的子字符串即可。
对我有用。
关于hash - 种子 info_hash 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10191480/