Sha256 in Objective-C for iPhone

Viewed 18766

When I use this code to create a sha256 of a string

unsigned char hashedChars[32];
NSString *inputString;
inputString = [NSString stringWithFormat:@"hello"];
NSData * inputData = [inputString dataUsingEncoding:NSUTF8StringEncoding];
CC_SHA256(inputData.bytes, inputData.length, hashedChars);

It returns the hash correctly, but I need to insert a string like this \x00\x25\x53 and in this case, the function returns a sha256 of empty string because the specified encoding cannot be used to convert the receiver.

Now, my question is:How to insert this special characters for generate a correct hash? Thanks

4 Answers

It's important to know that you need to import:

#import <CommonCrypto/CommonDigest.h>

Hope this help!

Related