Re: [OBJC Newbie] - MD5 Digest
Re: [OBJC Newbie] - MD5 Digest
- Subject: Re: [OBJC Newbie] - MD5 Digest
- From: Andreas Mayer <email@hidden>
- Date: Wed, 31 May 2006 20:07:02 +0200
Am 31.05.2006 um 16:13 Uhr schrieb Graham:
I need a class/framework to create an MD5 digest of a String.
//
// NSData_AMDigest.h
//
#import <Foundation/Foundation.h>
@interface NSData (AMDigest)
- (NSData *)md5Digest;
- (NSData *)sha1Digest;
@end
//
// NSData_AMDigest.m
//
#import "NSData_AMDigest.h"
#include <openssl/evp.h>
#include <openssl/err.h>
@implementation NSData (AMDigest)
- (NSData *)md5Digest
{
// compute an MD5 digest.
EVP_MD_CTX mdctx;
unsigned char md_value[EVP_MAX_MD_SIZE];
unsigned int md_len;
EVP_DigestInit(&mdctx, EVP_md5());
EVP_DigestUpdate(&mdctx, [self bytes], [self length]);
EVP_DigestFinal(&mdctx, md_value, &md_len);
return [NSData dataWithBytes: md_value length: md_len];
}
- (NSData *)sha1Digest
{
// compute an SHA1 digest.
EVP_MD_CTX mdctx;
unsigned char md_value[EVP_MAX_MD_SIZE];
unsigned int md_len;
EVP_DigestInit(&mdctx, EVP_sha1());
EVP_DigestUpdate(&mdctx, [self bytes], [self length]);
EVP_DigestFinal(&mdctx, md_value, &md_len);
return [NSData dataWithBytes: md_value length: md_len];
}
@end
Andreas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden