Last active
March 30, 2022 11:09
-
-
Save canaksoy/8eee46014500b063a18758afa5f5fcb1 to your computer and use it in GitHub Desktop.
sha256 hash objective-c ios xcode
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
-(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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hope you don't mind, I reposted this here: https://stackoverflow.com/a/60856103/8047
Thank you!