import --> #import CommonCrypto/CommonDigest.h
then make a Class Utility
in .h
#import Foundation/Foundation.h
#import CommonCrypto/CommonDigest.h
@interface Utilities : NSObject {
}
//generates md5 hash from a string
+ (NSString *) returnMD5Hash:(NSString*)concat;
@end
##############################################################
in .m
#import "Utilities.h"
@implementation Utilities
//generate md5 hash from string
+ (NSString *) returnMD5Hash:(NSString*)concat {
const char *concat_str = [concat UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(concat_str, strlen(concat_str), result);
NSMutableString *hash = [NSMutableString string];
for (int i = 0; i < 16; i++)
[hash appendFormat:@"%02X", result[i]];
return [hash lowercaseString];
}
@end
#######################
in the main Class
NSString *myMD5String = [Utilities returnMD5Hash:@"test"];
NSLog(@" myMD5String ----------------------- %@",myMD5String);
And Its Done , Happy Coding :)
No comments:
Post a Comment