Created
October 25, 2013 23:37
-
-
Save priore/7163455 to your computer and use it in GitHub Desktop.
SHA1 encode NSString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SHA1 | |
#import <CommonCrypto/CommonDigest.h> | |
- (NSString*)getSHA1WithString:(NSString*)string | |
{ | |
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; | |
uint8_t digest[CC_SHA1_DIGEST_LENGTH]; | |
CC_SHA1(data.bytes, (CC_LONG)data.length, digest); | |
NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2]; | |
for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) | |
{ | |
[output appendFormat:@"%02x", digest[i]]; | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment