How to encrypt a String to a SHA-1 Encrypted in iPhone
How to encrypt a String to a SHA-1 Encrypted in iPhone
- Subject: How to encrypt a String to a SHA-1 Encrypted in iPhone
- From: Tharindu Madushanka <email@hidden>
- Date: Sat, 27 Nov 2010 13:47:20 +0530
Hi,
In order to get this I found following code, but I need to import some
frameworks into my code. Could somebody kindly point how can achieve SHA-1
Encrypted string in iPhone. I get few errors compiling since I do not have
necessary framework to use this.. :(
+(NSString *)stringToSha1:(NSString *)str{
// data to Hash
NSMutableData *dataToHash = [str
dataUsingEncoding:NSUTF8StringEncoding];
unsigned char hashBytes[CC_SHA1_DIGEST_LENGTH];
CC_SHA1([dataToHash bytes], [dataToHash length], hashBytes);
NSData *encodedData = [NSData dataWithBytes:hashBytes
length:CC_SHA1_DIGEST_LENGTH];
[dataToHash release];
NSString *encodedStr = [NSString stringWithUTF8String:[encodedData
bytes]];
//NSString *encodedStr = [[NSString alloc] initWithBytes:[encodedData
bytes]
//
length:[encodedData length] encoding: NSUTF8StringEncoding];
NSLog(@"ENCODED SHA-1: %@", encodedStr);
return encodedStr;
}
Thank you,
Tharindu.
_______________________________________________
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