[英]Extract the hash from Torrent File in ruby
我希望提取torrent文件的哈希標識符。
特別是,我正在尋找在打開一個torrent信息對話框中顯示在Transmission / uTorrent中的相同哈希(看起來像這樣:7b435a6f051dec092a6ee440d793bfed6696cfa1)
我認為這是來自torrent文件的信息詞典的SHA1哈希。 如果我要將二進制文件數據從一個字節解析為另一個字節,那么執行SHA1哈希加密我就可以得到它。
有沒有人有更好的理解或有一些代碼可以做到這一點?
使用bencode gem:
require 'bencode'
require 'digest/sha1'
meta = BEncode.load_file(file) # File or file path
info_hash = Digest::SHA1.hexdigest(meta["info"].bencode)
你可以試試RubyTorrent ,這里有一個如何從.torrent文件轉儲元數據的例子: https : //github.com/dydx/RubyTorrent/blob/master/dump-metainfo.rb
還有一個bencode gem可用於解析.torrent文件。
使用鞭炮寶石
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.