Re: How to uniquely determine MD5-sum of a dict?
Re: How to uniquely determine MD5-sum of a dict?
- Subject: Re: How to uniquely determine MD5-sum of a dict?
- From: "I. Savant" <email@hidden>
- Date: Tue, 16 Sep 2008 15:25:09 -0400
On Tue, Sep 16, 2008 at 2:40 PM, Arthur C. <email@hidden> wrote:
> I have an NSDictionary that has to be written to disk, distributed and read in again.
> I would like to add an MD5 sum to the dictionary to make sure it has not been modified/corrupted on the way. That can be done by making NSData using NSArchiver and then passing it to MD5() from <openssl/md5.h>.
>
> But, the order in which keys/values are stored in the dict is not fixed. I would like to know if there is a simple way to get a unique (reproducable) MD5-sum.
I'd try adding a category method that gets all the dict's keys,
sorts the keys array, creates an array consisting of the (now-sorted)
key, value-for-that-key, key, value-for-that-key, key,
value-for-that-key ..., then archives the array, then gets the MD5 sum
from that archived array. In other words, the array would simply hold
a series of key string objects, then the object for that key ... for
every key in your sorted key list.
... but then, there might be a far easier way of doing it than that.
:-) Just a thought.
--
I.S.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden