objective c - Is there a MD5 library that doesn't require the whole input at the same time? -


i'm working on objective c cocoa application. tested cc_md5 in commoncrypto, , worked fine; however, when gave 5 gygabyte file it, whole computer froze , crashed. md5 algorithm processes input 512-byte chunks , doesn't require input @ once. there library in objective c or c asks next 512-byte chunk instead of taking input @ once?

there great thread on calculating md5 of large files in obj-c here: http://www.iphonedevsdk.com/forum/iphone-sdk-development/17659-calculating-md5-hash-large-file.html

here solution came there:

+(nsstring*)filemd5:(nsstring*)path {     nsfilehandle *handle = [nsfilehandle filehandleforreadingatpath:path];     if( handle== nil ) return @"error getting file md5"; // file didnt exist      cc_md5_ctx md5;      cc_md5_init(&md5);      bool done = no;     while(!done)     {         nsautoreleasepool * pool = [nsautoreleasepool new];         nsdata* filedata = [handle readdataoflength: chunk_size ];         cc_md5_update(&md5, [filedata bytes], [filedata length]);         if( [filedata length] == 0 ) done = yes;                 [pool drain];     }     unsigned char digest[cc_md5_digest_length];     cc_md5_final(digest, &md5);     nsstring* s = [nsstring stringwithformat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",                    digest[0], digest[1],                     digest[2], digest[3],                    digest[4], digest[5],                    digest[6], digest[7],                    digest[8], digest[9],                    digest[10], digest[11],                    digest[12], digest[13],                    digest[14], digest[15]];     return s; } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -