March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
21
Task/SHA-256/Objective-C/sha-256.m
Normal file
21
Task/SHA-256/Objective-C/sha-256.m
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#import <CommonCrypto/CommonHMAC.h>
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||
NSString* key = @"secret";
|
||||
NSString* data = @"Message";
|
||||
|
||||
const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding];
|
||||
const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding];
|
||||
unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
|
||||
CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
|
||||
|
||||
NSMutableString* result = [NSMutableString stringWithCapacity:(CC_SHA256_DIGEST_LENGTH * 2)];
|
||||
|
||||
for(CC_LONG i = 0; i < CC_SHA256_DIGEST_LENGTH; i++)
|
||||
[result appendFormat:@"%02x", cHMAC[i]];
|
||||
|
||||
NSLog(@"Sha-256: %@", result);
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue