So, I need to generate a Sha256 password in Objective-C, and I cannot figure out how to do this! Is there something easy I'm just missing?
I tried to implement the following method (which was written for the iPhone, but I thought maybe it will work cross-platform, as Objective-C code does)
-(NSString*)sha256HashFor:(NSString*)input { const char* str = [input UTF8String]; unsigned char result[CC_SHA256_DIGEST_LENGTH]; CC_SHA256(str, 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; }
But it just spat out errors that CC_SHA256_DIGEST_LENGTH is an undeclared identifier.
passwords objective-c encryption password-hash macos sha256
garetmckinley
source share