首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Objective-C中Torrent文件的SHA1散列问题

Objective-C中Torrent文件的SHA1散列问题
EN

Stack Overflow用户
提问于 2013-04-16 22:14:16
回答 1查看 412关注 0票数 1

由于µtorrent的响应系统在通过磁铁链接或torrent文件发送时存在不足,即完全没有添加重复torrent的消息,因此我尝试在torrent文件发送之前从torrent文件中获取散列,并将其与当前作业列表进行比较。我目前的代码返回了一个不正确的哈希,我不知道为什么。这是我正在使用的代码。

我试图发送一个散列为"dc9202f98aea7420a2872655c8f7184401e2a9c8“的文件,这段代码每次运行都会返回大约30个散列中的一个。

代码语言:javascript
复制
+ (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;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-18 01:59:41

是什么让你认为BT信息散列是SHA1而不仅仅是片段散列?

引用BEP-0003

代码语言:javascript
复制
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. 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16039460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档