从 Erlang 的 torrent 文件中的信息字典获取 SHA 哈希值
我一直在尝试在 Erlang 中解析一个 torrent 文件,到目前为止,我能够提取所有一般信息,如 torrent 名称、文件(长度、路径、名称)、跟踪器链接...
唯一困扰我的是sha1 哈希值。我在线检查了很多网站,根据规范,“info”字典是需要散列的。 但是,我仍然对分隔符感到困惑。 d 和 e 应该包括还是不包括?
最后,我认为如何从文件中读取数据很重要,现在我将文件作为二进制文件读取,然后在解析数据之前将其转换为列表。如果生成的话,这会改变/破坏哈希值吗?是否有合适的数据类型(二进制/列表)能够正确提取信息字典。
提前致谢。
I have been trying to parse a torrent file in Erlang, So far I was able to extract all the general info like torrent name, files(length, path, name), tracker link...
The only thing that is bothering me is the sha1 hash value. I checked many websites online and according to the specification the "info" dictionary is what needs to be hashed.
However, I'm still confused by the delimiters. Should d and e be included or not?
Finally, I think that it matters how the data is read in from the file, right now I read the file as a binary then convert it to a list before parsing the data. Does this change/corrupt the hash if generated? Is there a suitable data type (Binary / List) to be able to correctly extract the info dictionary.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
信息字典中的所有内容都应该进行哈希处理,包括第一个和最后一个字符; d 和 e。
Everything from the info dictionary should be hashed including the first and last characters; the d and e.
我不确定我是否完全理解您想要的内容,但我不是 torrent 文件专家。要从二进制文件中获取 SHA1:
http://www.erlang.org/doc/man/crypto.html
如果您需要 SHA2:
http://steve.vinoski.net/code/sha2.html
I´m not sure I understood exactly what you want, but i´m not an torrent file expert. For getting the SHA1 from a binary:
http://www.erlang.org/doc/man/crypto.html
if you need SHA2:
http://steve.vinoski.net/code/sha2.html