[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MD5

From: David Ayers
Subject: Re: MD5
Date: Thu, 23 Jan 2003 13:47:15 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3a) Gecko/20021212

Richard Frith-Macdonald wrote:

I already added a simple category of NSData to the Additions library, consisting only of an -MD5Digest method returning an NSData object.

Cool, I'll try to get a gsweb patch in soon...

I'm not sure what the other methods are supposed to do exactly ... the string encoding makes sense where the string is the input to the digest ... but what to do when producing string output? I don't think there is any standard format for representing a digest as a string, unless it's to encode the bytes as pairs of hex digits. certainly, you can't just use [NSString-initWithData:encoding:] to produce a string as you have no guarantee that the bytes of the digest are valid characters in the encoding you specify.

Actually yes, I did fall into that trap here :-). What I actually meant would probably be something like

@implementation NSData (MD5)
- (NSString *)md5String
return [[self md5Digest] hexadecimalStringRepresentation]
and at that point the encoding wouldn't hav to be dealt with.

and maybe:
@implementation NSString (MD5)
- (NSString *)md5StringUsingEncoding: (NSStringEncoding) enc
 return [[self dataUsingEncoding: enc] md5String];
- (NSString *)md5String
 return [[self dataUsingEncoding: [isa defaultCStringEncoding] md5String];

reply via email to

[Prev in Thread] Current Thread [Next in Thread]