Skip to content

Instantly share code, notes, and snippets.

@hjazz
Created March 9, 2014 07:51
Show Gist options
  • Save hjazz/9444236 to your computer and use it in GitHub Desktop.
Save hjazz/9444236 to your computer and use it in GitHub Desktop.
sha256 string
#import <CommonCrypto/CommonDigest.h>
+ (NSString*)sha256HashFor:(NSString*)input
{
const char* str = [input UTF8String];
unsigned char result[CC_SHA256_DIGEST_LENGTH];
CC_SHA256(str, (unsigned int)strlen(str), result);
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH*2];
for(int i = 0; i<CC_SHA256_DIGEST_LENGTH; i++)
{
[ret appendFormat:@"%02x",result[i]];
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment