[英]info_hash calculated for torrent incorrect
OK I've searched all related questions, and source code where available, just stuck. 好的,我已经搜索了所有相关问题,并且找到了可用的源代码,只是卡住了。 I'm using this code from a related question: How to calculate the hash value of a torrent using Java
我正在使用以下相关问题中的代码: 如何使用Java计算torrent的哈希值
to build the SHA-1 hash. 生成SHA-1哈希。
Then I'm doing this to encode it, to be included in the tracker request: 然后,我要对其进行编码,以将其包含在跟踪器请求中:
URLCodec c = new org.apache.commons.codec.net.URLCodec();
URLCodec c =新的org.apache.commons.codec.net.URLCodec(); return new String(c.encode(info_hash));
返回新的String(c.encode(info_hash));
But the tracker replies with no peers. 但是跟踪器没有其他人答复。 By tracing uTorrent, I can see the correct hash for my torrent file is: T%7f%bc%a6%92%bb%8a%8b%2aL%b9%a3%0f%a59%f3%98%e6%0c%eb
通过跟踪uTorrent,我可以看到我的种子文件的正确哈希是:T%7f%bc%a6%92%bb%8a%8b%2aL%b9%a3%0f%a59%f3%98%e6%0c% eb
But my code outputs: %E4%AF%3C%96%9E%D2%BAJt%C0%C3%B4%12%93%D4h%3B%9A%2CF 但是我的代码输出:%E4%AF%3C%96%9E%D2%BAJt%C0%C3%B4%12%93%D4h%3B%9A%2CF
Any ideas why this won't work? 任何想法为什么这行不通?
private string encodeInfoHash(string code)
{
//string code = "78820B24672757A60BEF15252E93F3D0C4DEB5C3";
byte[] codeB = Encoding.Default.GetBytes(code);
string info_hash_encoded = null;
for (int i = 0; i < code.Length; i += 2)
{
string tmpCode = code[i].ToString() + code[i + 1].ToString();
int j = Convert.ToInt32(tmpCode, 16);
char s1 = (char)j;
bool isSpecChar = false;
if (s1.ToString() == "." || s1.ToString() == "-" || s1.ToString() == "~")
isSpecChar = true;
if ((Char.IsLetter(s1) || Char.IsNumber(s1) || isSpecChar) && !Char.IsControl(s1) && j <= 127)
{
info_hash_encoded += s1.ToString();
}
else
{
info_hash_encoded += "%" + tmpCode.ToLower();
}
}
return info_hash_encoded;
}
I use C# , you can read my blog for more detail http://hello.xiaoyezi.xyz/urlencode-the-info_hash.html 我使用C#,您可以阅读我的博客以了解更多详细信息http://hello.xiaoyezi.xyz/urlencode-the-info_hash.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.