简体   繁体   English

Torrent 文件中的 info_Hash 到底是什么

[英]What exactly is the info_Hash in a torrent file

I am reading lately a lot about hash from torrents, and magnetic links, etc. But there is a question I don't understand.我最近阅读了很多关于种子和磁力链接等的哈希值。但是有一个我不明白的问题。

I have:我有:

  • hash of a file文件的哈希值
  • and the infohash of a torrent和洪流的信息哈希

Is the infohash = hash of the file ?是文件的infohash = hash 吗?

If yes what if the torrent describes 6 Files to download?如果是,如果 torrent 描述了 6 个要下载的文件怎么办?

If no what does it stand for?如果不是,它代表什么?

So I finally figured it out.所以我终于想通了。

The “infohash” is the SHA1 Hash over the part of a torrent file that includes: “infohash”是包含以下内容的 torrent 文件部分的 SHA1 哈希:

  1. ITEM: length(size) and path (path with filename) ITEM:长度(大小)和路径(带文件名的路径)
  2. Name: The name to search for名称:要搜索的名称
  3. Piece length: The length(size) of a single piece件长:单件的长度(尺寸)
  4. Pieces: SHA1 Hash of EVERY piece of this torrent Pieces:这个洪流的每一部分的SHA1哈希
  5. Private: flag for restricted access私有:限制访问的标志

To show this a little more I took a random torrent file and used the “BEncode Editor” from Ultima to make it more clearly to me.为了更多地展示这一点,我随机选取了一个 torrent 文件,并使用了 Ultima 的“BEncode 编辑器”使其更清晰。

B编码编辑器

As you can see the the red box marked the information part of the torrent file.如您所见,红色框标记了 torrent 文件的信息部分。 The torrent file includes not the Hash of the items, but the hashes of every piece. Torrent 文件不包含项目的哈希值,而是包含每个片段的哈希值。

  • For item1 with: 1069496548对于 item1:1069496548
  • and item2 with: 223和 item2 与:223
  • It is together: 1069496771一起:1069496771
  • With a piece size of: 524288单件尺寸:524288
  • There are 2040 pieces.有 2040 件。 (1069496771/524288=2039.9032 approximately) (约1069496771/524288=2039.9032)
  • The pieces section includes 40800 byte of data what are 81600 + 2 chars in the file.片段部分包括 40800 字节的数据,即文件中的 81600 + 2 个字符。
  • the +2 because 0x marks that this is hexadecimal. +2 因为 0x 标记这是十六进制。
  • A SHA1 hash has 40 0x chars or 20 Byte of data what are 2040 SHA1 hashes. SHA1 哈希有 40 个 0x 字符或 20 字节的数据,即 2040 SHA1 哈希。

在此处输入图片说明

I am sorry that this information is about a torrent that leads to a illegal movie, but i wanted to use a torrent that realy exists.很抱歉,这些信息是关于导致非法电影的洪流,但我想使用真实存在的洪流。

I wanted to add another example, slightly more concrete.我想添加另一个例子,稍微具体一点。

We start with one of the smallest .torrent files i have:我们从我拥有的最小的.torrent文件之一开始:

64 34 3A 69 6E 66 6F 64 35 3A 66 69 6C 65 73 6C 64 36 3A 6C 65 6E 67 74 
68 69 36 31 35 65 34 3A 70 61 74 68 6C 32 36 3A 66 72 65 65 20 61 75 64 
69 6F 62 6F 6F 6B 20 76 65 72 73 69 6F 6E 2E 74 78 74 65 65 64 36 3A 6C 
65 6E 67 74 68 69 33 39 33 34 31 37 65 34 3A 70 61 74 68 6C 36 31 3A 57 
61 72 63 72 61 66 74 5F 20 4F 66 66 69 63 69 61 6C 20 4D 6F 76 69 65 20 
4E 6F 76 65 6C 69 7A 61 74 69 6F 6E 20 62 79 20 43 68 72 69 73 74 69 65 
20 47 6F 6C 64 65 6E 2E 65 70 75 62 65 65 65 34 3A 6E 61 6D 65 36 31 3A 
57 61 72 63 72 61 66 74 5F 20 4F 66 66 69 63 69 61 6C 20 4D 6F 76 69 65 
20 4E 6F 76 65 6C 69 7A 61 74 69 6F 6E 20 62 79 20 43 68 72 69 73 74 69 
65 20 47 6F 6C 64 65 6E 20 45 50 55 42 31 32 3A 70 69 65 63 65 20 6C 65 
6E 67 74 68 69 31 30 34 38 35 37 36 65 36 3A 70 69 65 63 65 73 32 30 3A 
43 92 4C 22 BB 42 9E EA BD FF 66 C6 79 4C 29 E4 F9 D0 F3 B9 65 65

If we decode the BEncoding:如果我们解码 BEncoding:

64                                             ; DICTIONARY (d)
|  34 3A 69 6E 66 6F                           ;  - 4:info
|  64                                          ;  - DICTIONARY (d)
|  |  35 3A 66 69 6C 65 73                     ;     - 5:files
|  |  6C                                       ;     - LIST (l)
|  |  |  64                                    ;        - DICTIONARY (d)
|  |  |  |  36 3A 6C 65 6E 67 74 68            ;           - 6:length
|  |  |  |  69 36 31 35 65                     ;           - i615e
|  |  |  |  34 3A 70 61 74 68                  ;           - 4:path
|  |  |  |  6C                                 ;           - LIST (l)
|  |  |  |  |  32 36 3A 66 72 65 65 20 61 75   ;              - 26:free audiobook verison.txt
|  |  |  |  |  64 69 6F 62 6F 6F 6B 20 76 65   ;                  
|  |  |  |  |  72 73 69 6F 6E 2E 74 78 74      ;                  
|  |  |  |  65                                 ;              - END (e)
|  |  |  65                                    ;           - END (e)
|  |  |  64                                    ;           - DICTIONARY (d)
|  |  |  |  36 3A 6C 65 6E 67 74 68            ;              - 6:length
|  |  |  |  69 33 39 33 34 31 37 65            ;              - i393417e
|  |  |  |  34 3A 70 61 74 68                  ;              - 4:path
|  |  |  |  6C                                 ;              - LIST (l)
|  |  |  |  |  36 31 3A 57 61 72 63 72 61 66   ;                 - 61:Warcraft_ Official Movie Novelization by Christie Golden.epub
|  |  |  |  |  74 5F 20 4F 66 66 69 63 69 61   ;                  
|  |  |  |  |  6C 20 4D 6F 76 69 65 20 4E 6F   ;                  
|  |  |  |  |  76 65 6C 69 7A 61 74 69 6F 6E   ;                  
|  |  |  |  |  20 62 79 20 43 68 72 69 73 74   ;                  
|  |  |  |  |  69 65 20 47 6F 6C 64 65 6E 2E   ;                  
|  |  |  |  |  65 70 75 62                     ;                  
|  |  |  |  65                                 ;              - END (e)
|  |  |  65                                    ;           - END (e)
|  |  65                                       ;        - END (e)
|  |  34 3A 6E 61 6D 65                        ;        - 4:name
|  |  36 31 3A 57 61 72 63 72 61 66            ;        - 61:Warcraft_ Official Movie Novelization by Christie Golden EPUB 
|  |  74 5F 20 4F 66 66 69 63 69 61            ;         
|  |  6C 20 4D 6F 76 69 65 20 4E 6F            ;         
|  |  76 65 6C 69 7A 61 74 69 6F 6E            ;         
|  |  20 62 79 20 43 68 72 69 73 74            ;         
|  |  69 65 20 47 6F 6C 64 65 6E 20            ;         
|  |  45 50 55 42                              ;          
|  |  31 32 3A 70 69 65 63 65 20 6C            ;        - 12:piece length
|  |  65 6E 67 74 68                           ;         
|  |  69 31 30 34 38 35 37 36 65               ;        - i10485765e
|  |  36 3A 70 69 65 63 65 73                  ;        - 6:pieces
|  |  32 30 3A 43 92 4C 22 BB 42 9E            ;        - 20:43 92 4C 22 BB 42 9E EA BD FF 66 C6 79 4C 29 E4 F9 D0 F3 B9 65 65
|  |  EA BD FF 66 C6 79 4C 29 E4 F9            ;
|  |  D0 F3 B9                                 ;
|  65                                          ;     - END (e)
65                                             ;  - END (e)

Or, in pseudo-json:或者,在伪 json 中:

{
   info: {
      files: [
         { length: 615,    path: ["free audiobook verison.txt"] },
         { length: 393417, path: ["Warcraft_ Official Movie Novelization by Christie Golden.epub"] }
      ],
      name:           "Warcraft_ Official Movie Novelization by Christie Golden EPUB",
      "piece length": 10485765,
      pieces:         43 92 4C 22 BB 42 9E EA BD FF 66 C6 79 4C 29 E4 F9 D0 F3 B9 65 65
   }
}

InfoHash is hash of the info InfoHash 是信息的散列

The InfoHash is the SHA-1 hash of the info dictionary contents. InfoHash信息字典内容的 SHA-1 哈希。

We want to take the SHA-1 hash of value of the info dictionary key:我们想要获取info字典键值的 SHA-1 哈希

64                                          ;  - DICTIONARY (d)
|  35 3A 66 69 6C 65 73                     ;     - 5:files
|  6C                                       ;     - LIST (l)
|  |  64                                    ;        - DICTIONARY (d)
|  |  |  36 3A 6C 65 6E 67 74 68            ;           - 6:length
|  |  |  69 36 31 35 65                     ;           - i615e
|  |  |  34 3A 70 61 74 68                  ;           - 4:path
|  |  |  6C                                 ;           - LIST (l)
|  |  |  |  32 36 3A 66 72 65 65 20 61 75   ;              - 26:free audiobook verison.txt
|  |  |  |  64 69 6F 62 6F 6F 6B 20 76 65   ;                  
|  |  |  |  72 73 69 6F 6E 2E 74 78 74      ;                  
|  |  |  65                                 ;              - END (e)
|  |  65                                    ;           - END (e)
|  |  64                                    ;           - DICTIONARY (d)
|  |  |  36 3A 6C 65 6E 67 74 68            ;              - 6:length
|  |  |  69 33 39 33 34 31 37 65            ;              - i393417e
|  |  |  34 3A 70 61 74 68                  ;              - 4:path
|  |  |  6C                                 ;              - LIST (l)
|  |  |  |  36 31 3A 57 61 72 63 72 61 66   ;                 - 61:Warcraft_ Official Movie Novelization by Christie Golden.epub
|  |  |  |  74 5F 20 4F 66 66 69 63 69 61   ;                  
|  |  |  |  6C 20 4D 6F 76 69 65 20 4E 6F   ;                  
|  |  |  |  76 65 6C 69 7A 61 74 69 6F 6E   ;                  
|  |  |  |  20 62 79 20 43 68 72 69 73 74   ;                  
|  |  |  |  69 65 20 47 6F 6C 64 65 6E 2E   ;                  
|  |  |  |  65 70 75 62                     ;                  
|  |  |  65                                 ;              - END (e)
|  |  65                                    ;           - END (e)
|  65                                       ;        - END (e)
|  34 3A 6E 61 6D 65                        ;        - 4:name
|  36 31 3A 57 61 72 63 72 61 66            ;        - 61:Warcraft_ Official Movie Novelization by Christie Golden EPUB 
|  74 5F 20 4F 66 66 69 63 69 61            ;         
|  6C 20 4D 6F 76 69 65 20 4E 6F            ;         
|  76 65 6C 69 7A 61 74 69 6F 6E            ;         
|  20 62 79 20 43 68 72 69 73 74            ;         
|  69 65 20 47 6F 6C 64 65 6E 20            ;         
|  45 50 55 42                              ;          
|  31 32 3A 70 69 65 63 65 20 6C            ;        - 12:piece length
|  65 6E 67 74 68                           ;         
|  69 31 30 34 38 35 37 36 65               ;        - i10485765e
|  36 3A 70 69 65 63 65 73                  ;        - 6:pieces
|  32 30 3A 43 92 4C 22 BB 42 9E            ;        - 20:43 92 4C 22 BB 42 9E EA BD FF 66 C6 79 4C 29 E4 F9 D0 F3 B9 65 65
|  EA BD FF 66 C6 79 4C 29 E4 F9            ;
|  D0 F3 B9                                 ;
65                                          ;     - END (e)

We run all these bytes together:我们一起运行所有这些字节:

64 35 3A 66 69 6C 65 73 6C 64 36 3A 6C 65 6E 67 74 68 69 36 31 35 65 34 
3A 70 61 74 68 6C 32 36 3A 66 72 65 65 20 61 75 64 69 6F 62 6F 6F 6B 20 
76 65 72 73 69 6F 6E 2E 74 78 74 65 65 64 36 3A 6C 65 6E 67 74 68 69 33 
39 33 34 31 37 65 34 3A 70 61 74 68 6C 36 31 3A 57 61 72 63 72 61 66 74 
5F 20 4F 66 66 69 63 69 61 6C 20 4D 6F 76 69 65 20 4E 6F 76 65 6C 69 7A 
61 74 69 6F 6E 20 62 79 20 43 68 72 69 73 74 69 65 20 47 6F 6C 64 65 6E 
2E 65 70 75 62 65 65 65 34 3A 6E 61 6D 65 36 31 3A 57 61 72 63 72 61 66 
74 5F 20 4F 66 66 69 63 69 61 6C 20 4D 6F 76 69 65 20 4E 6F 76 65 6C 69 
7A 61 74 69 6F 6E 20 62 79 20 43 68 72 69 73 74 69 65 20 47 6F 6C 64 65 
6E 20 45 50 55 42 31 32 3A 70 69 65 63 65 20 6C 65 6E 67 74 68 69 31 30 
34 38 35 37 36 65 36 3A 70 69 65 63 65 73 32 30 3A 43 92 4C 22 BB 42 9E 
EA BD FF 66 C6 79 4C 29 E4 F9 D0 F3 B9 65

And then take the SHA-1 hash to generate a 160-bit (20-byte) digest:然后使用 SHA-1 哈希生成一个 160 位(20 字节)的摘要:

7EDA978ED7628595BB91C48B947F025BAE78CB77

Which is the right answer:哪个是正确答案:

在此处输入图片说明

Here's how to pull the pertinent segment of a *.torrent datum for a bittorrent “info hash”.以下是如何提取 *.torrent 数据的相关部分以获取 bittorrent“信息哈希”。

I made this for an example.我以这个为例。

0000000: 6438 3A61 6E6E 6F75 6E63 6530 3A31 303A  d8:announce0:10:
0000010: 6372 6561 7465 6420 6279 3133 3A6D 6B74  created by13:mkt
0000020: 6F72 7265 6E74 2031 2E30 3133 3A63 7265  orrent 1.013:cre
0000030: 6174 696F 6E20 6461 7465 6931 3537 3037  ation datei15707
0000040: 3530 3238 3565 343A 696E 666F 6436 3A6C  50285e4:infod6:l
0000050: 656E 6774 6869 3230 6534 3A6E 616D 6534  engthi20e4:name4
0000060: 3A70 7269 7631 323A 7069 6563 6520 6C65  :priv12:piece le
0000070: 6E67 7468 6932 3632 3134 3465 363A 7069  ngthi262144e6:pi
0000080: 6563 6573 3230 3AF1 D7EE 4236 3434 D06F  eces20:...B644.o
0000090: 27C4 BBAD 87F0 F089 7A22 2B37 3A70 7269  '.......z"+7:pri
00000a0: 7661 7465 6931 6565 65                   vatei1eee

The content of the “info” key is between (inclusive) offsets 0x4D and 0xA7. “info”键的内容在(包括)偏移量 0x4D 和 0xA7 之间。 So…所以…

#!/crit/shell/bsh
bbe  \
    -e '
        d 0x0 0x4C ;
        d 0xA8 * ;
      '  \
    ${example}   \
 |
shasum  -a 1  -b

You should see this:你应该看到这个:

1799a58b9f8ff2b9b9bcecd0d438c5f37f19a31c *-

Here is the xxd output, in–lieu of shasum , for more elucidation:这是xxd输出,代替shasum ,以供更多说明:

0000000: 6436 3A6C 656E 6774 6869 3230 6534 3A6E  d6:lengthi20e4:n
0000010: 616D 6534 3A70 7269 7631 323A 7069 6563  ame4:priv12:piec
0000020: 6520 6C65 6E67 7468 6932 3632 3134 3465  e lengthi262144e
0000030: 363A 7069 6563 6573 3230 3AF1 D7EE 4236  6:pieces20:...B6
0000040: 3434 D06F 27C4 BBAD 87F0 F089 7A22 2B37  44.o'.......z"+7
0000050: 3A70 7269 7661 7465 6931 6565            :privatei1ee

You can refer to The BitTorrent Protocol Specification for an explanation, albeit a terse and rather grammatically inelegant one, as to their nomenclature and why the final 0x65 needs be excluded.您可以参考The BitTorrent Protocol Specification以了解有关它们的命名以及为什么需要排除最终 0x65 的解释,尽管这很简洁且在语法上相当不雅。
Concisely: the entire datum is encased in a pair of US-ASCII 'd' and 'e';简而言之:整个数据都包含在一对 US-ASCII 'd' 和 'e' 中; the content of the “info” key, or field, is similarly so encased. “info”键或字段的内容也同样如此。 You want everything between the first 0x64 — 'd', — which succeeds the US-ASCII string 4:info , and the terminal 0x65 — 'e', — which is paired with the aforementioned 0x64.您需要第一个 0x64 — 'd', — 它在 US-ASCII 字符串4:info ,以及终端 0x65 — 'e', — 与前面提到的 0x64 配对。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM