Extract hash from torrent file in ruby

I was hoping to extract the hash identifier of the torrent file.

In particular, I am looking for the same hash that appears in Transmission / uTorrent when opening the torrent information exchange (it looks like this: 7b435a6f051dec092a6ee440d793bfed6696cfa1)

I think this is a SHA1 hash from the information dictionary in the torrent file. If I were to analyze binary data from one byte to another, I would perform SHA1 hash encryption, which I could get.

Does anyone have a better understanding or is there some kind of code that could do this?

+4
source share
3 answers

Using bencode gem:

require 'bencode' require 'digest/sha1' meta = BEncode.load_file(file) # File or file path info_hash = Digest::SHA1.hexdigest(meta["info"].bencode) 
+2
source

You can try RubyTorrent , there is an example of how to dump metadata from a .torrent file here: https://github.com/dydx/RubyTorrent/blob/master/dump-metainfo.rb

There is also a bencode gem that can be used to analyze torrent files.

+1
source

Using firecracker gem

 require "firecracker" require "bencode_ext" require 'open-uri' torrent = open(link).read # Get the info_hash from torrent file info_hash = Firecracker.hash(torrent.bdecode) puts "Info Hash = " + info_hash 
0
source

All Articles