我有个torrent文件。它的info_hash值是87bebe2a6dfa25c8d8075893c4c6e05878cccb4a。
我需要从UDP追踪器获取对等点,但在UDP追踪器协议中,info_hash的大小应该是20。那么如何转换它呢?
我使用bitcomet下载,使用wireshark捕获消息。
这是我得到的东西:
0000 80 f6 2e cd a7 81 8c ec 4b 6d 8f 0f 08 00 45 00 .ö.ͧ..ìKm....E.
0010 00 7e 41 a9 00 00 80 11 00 00 c0 a8 29 49 6d 4a .~A©......À¨)ImJ
0020 46 bc 41 cd 4c 3e 00 6a 9e 73 64 31 3a 61 64 32 F¼AÍL>.j.sd1:ad2
0030 3a 69 64 32 30 3a f7 66 44 1b 73 41 09 0d 1b 10 :id20:÷fD.sA....
0040 84 1d a6 7f 47 e8 4c b7 63 86 36 3a 74 61 72 67 ..¦.GèL·c.6:targ
0050 65 74 32 30 3a 08 99 bb e4 8c be f6 f2 e4 ef 7b et20:..»ä.¾öòäï{
0060 e2 59 80 b8 17 b3 48 9c 78 65 31 3a 71 39 3a 66 âY.¸.³H.xe1:q9:f
0070 69 6e 64 5f 6e 6f 64 65 31 3a 74 38 3a 0f ea 8a ind_node1:t8:.ê.
0080 c2 86 ff 4c 37 31 3a 79 31 3a 71 65 Â.ÿL71:y1:qe根据UDP Tracker协议,我捕获的info_hash是7341090d1b1084 1da67f47e84cb76386363a7461。它与实际值87bebe2a6dfa25c8d8075893c4c6e05878cccb4a完全不同。我说错了吗?我确信消息的目的地是UDP跟踪器,因为它的长度是98。
我尝试使用Java进行转换。代码如下:
public static String IHToString(String v) throws Exception{
byte[] b=new byte[20];
for(int i=0;i<b.length;i++) {
String n=v.substring(i*2, i*2+2);
int j=(byte)Integer.parseInt(n, 16) & 0xff;
b[i]=(byte)j;
}
return new String(b,"ASCII");
}
String s1=IHToString("87bebe2a6dfa25c8d8075893c4c6e05878cccb4a");
byte[] b1=s1.getByte("ASCII");显然是错的。
结果既不是7341090d1b1084 1da67f47e84cb76386363a7461也不是87bebe2a6dfa25c8d8075893c4c6e05878cccb4a。我真的对此感到厌烦。请帮帮我。-_-
发布于 2019-02-12 19:12:38
您的文件(87bebe...)的info_hash已经有20个字节。一个字节可以由两个十六进制数字表示。SHA-1散列的长度为160位(20字节)。
此哈希不同于您从UDP跟踪器协议获得的info_hash,因为它的计算方式不同。哈希是不能反转的。
有关更多详细信息,请参阅:http://www.bittorrent.org/beps/bep_0003.html和What exactly is the info_Hash in a torrent file
https://stackoverflow.com/questions/54648220
复制相似问题