[bittorrent] About getting the info hash value from a .torrent file
brian at dessent.net
Tue Oct 25 23:04:52 EDT 2005
FYP 2005 wrote:
> I found a correct sha1 algorithm written in Java(it just takes a
> string as argument).
> But I can't get the correct sha1 value from the algorithm when I hash
> all the bytes between the brackets.
> P.S. I just read in the bytes between the brackets into a StringBuffer
> and then convert the StringBuffer into a String.
> And pass the String into the sha1 algorithm.
Whatever method you use has to be 8-bit clean. The info key contains
raw binary data. So for example if you use C-style strings, you would
get incorrect results because the first \0 would erroneously signal the
end of the buffer. The correct way to handle it in a C-like language is
to allocate a raw buffer of memory and maintain the length of the string
seperately, and always use functions like memcpy() and not strcpy().
If your language has the capability of 8-bit-clean strings (as python
and perl do, for example) you can just use a regular string.
I have no idea what your code is doing, so it's impossible to say why
it's not working.
More information about the BitTorrent