-
Notifications
You must be signed in to change notification settings - Fork 0
/
HashSHA256.m
33 lines (23 loc) · 871 Bytes
/
HashSHA256.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
// HashSHA256.m
// monkeywrench
//
// Created by Nicolas Kline on 6/2/12.
// Copyright (c) 2012 Apptruism. All rights reserved.
//
#import "HashSHA256.h"
#import <CommonCrypto/CommonHMAC.h>
@implementation HashSHA256
- (NSString *) hashedValue :(NSString *) key andData: (NSString *) data {
const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
const char *cData = [data cStringUsingEncoding:NSUTF8StringEncoding];
unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
NSString *hash;
NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x", cHMAC[i]];
hash = output;
return hash;
}
@end