I've searched everywhere looking for a working JavaScript Bencode module and couldn't find one so I decided to write my own for the purpose of generating torrent info hashes.
The module works to the best of my knowledge as I wrote the functions to the specification.
Dictionary => Objects => Key/value pairs
List => Array Objects => number/value pairs
Integers => Number Objects
Strings...
Anyway, I decode the torrent file's data and then encode the decoded info key's value, next I use a SHA-1 module by Google API and the info hash never matches the original. I'm dumb founded.
I've tested my module thoroughly. I can decode the data pass it to my encode function and its and exact match to the original data but when I try to generate the hash from the encoded info section value I get a mismatch.
I do believe this is due to JavaScript's poor binary string handling and I have no idea how to diagnose or resolve this issue.
When I output the data from a get request depending on the content-type header the binary portion of the string displays differently and is the reason I've come to this conclusion.
I understand that the torrent file is UTF-8 character encoded but after that I'm helpless...
Thanks for any help in advance.
The torrent file is UTF-8 character encoded but parts of it are not. The "pieces" key in the info dictionary is strictly ASCII encoded, retrieving it as UTF-8 causes errors for me with [C] and will probably do the same to you with JavaScript.