由于µtorrent的响应系统在通过磁铁链接或torrent文件发送时存在不足,即完全没有添加重复torrent的消息,因此我尝试在torrent文件发送之前从torrent文件中获取散列,并将其与当前作业列表进行比较。我目前的代码返回了一个不正确的哈希,我不知道为什么。这是我正在使用的代码。
我试图发送一个散列为"dc9202f98aea7420a2872655c8f7184401e2a9c8“的文件,这段代码每次运行都会返回大约30个散列中的一个。
+ (NSString *) torrentHashFromFile:(NSData *)file
{
NSString * retVal = @"";
NSData * data = [BEncoding encodedDataFromObject:
[[BEncoding objectFromEncodedData:file]
objectForKey:@"info"]];
unsigned char hashBytes[CC_SHA1_DIGEST_LENGTH];
if (CC_SHA1([data bytes], (unsigned)[data length], hashBytes))
{
NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
{
[output appendFormat:@"%02x", hashBytes[i]];
}
retVal = output;
}
return retVal;
}发布于 2013-04-18 01:59:41
是什么让你认为BT信息散列是SHA1而不仅仅是片段散列?
引用BEP-0003:
info_hash
The 20 byte sha1 hash of the bencoded form of the info value from the metainfo file.
Note that this is a substring of the metainfo file. https://stackoverflow.com/questions/16039460
复制相似问题