Skip to content

Instantly share code, notes, and snippets.

@canaksoy
Last active March 30, 2022 11:09
Show Gist options
  • Save canaksoy/8eee46014500b063a18758afa5f5fcb1 to your computer and use it in GitHub Desktop.
Save canaksoy/8eee46014500b063a18758afa5f5fcb1 to your computer and use it in GitHub Desktop.
sha256 hash objective-c ios xcode
-(NSString*)sha256HashFor:(NSString*)input
{
const char* str = [input UTF8String];
unsigned char result[CC_SHA256_DIGEST_LENGTH];
CC_SHA256(str, (CC_LONG)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;
}
@drosenstark
Copy link

Hope you don't mind, I reposted this here: https://stackoverflow.com/a/60856103/8047

Thank you!

@zachvp
Copy link

zachvp commented Feb 3, 2021

Wow this is clutch, thanks a bunch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment