Anonymous user
SHA-256: Difference between revisions
Fixed to use digest instead of HMAC.
No edit summary |
(Fixed to use digest instead of HMAC.) |
||
Line 803:
=={{header|Objective-C}}==
Build with something like
<pre>
<lang objc>#import <CommonCrypto/CommonHMAC.h>▼
clang -o rosetta_sha256 rosetta_sha256.m /System/Library/Frameworks/Cocoa.framework/Cocoa
</pre>
or in XCode.
#import <CommonCrypto/CommonDigest.h>
NSString* key = @"secret";▼
const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding];▼
unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];▼
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]];▼
int main(int argc, char ** argv) {
NSLog(@"Sha-256: %@", result);▼
}</lang>▼
if (! CC_SHA256(rc, strlen(rc), buf)) {
NSLog(@"Failure...");
return -1;
}
}
return 0;
}
=={{header|OCaml}}==
|