Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,21 +1,19 @@
#import <CommonCrypto/CommonHMAC.h>
#import <Cocoa/Cocoa.h>
#import <CommonCrypto/CommonDigest.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);
int main(int argc, char ** argv) {
NSString * msg = @"Rosetta code";
unsigned char buf[CC_SHA256_DIGEST_LENGTH];
const char * rc = [msg cStringUsingEncoding:NSASCIIStringEncoding];
if (! CC_SHA256(rc, strlen(rc), buf)) {
NSLog(@"Failure...");
return -1;
}
NSMutableString * res = [NSMutableString stringWithCapacity:(CC_SHA256_DIGEST_LENGTH * 2)];
for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; ++i) {
[res appendFormat:@"%02x", buf[i]];
}
NSLog(@"Output: %@", res);
return 0;
}