fork download
  1. #import <objc/objc.h>
  2. #import <objc/Object.h>
  3. #import <Foundation/Foundation.h>
  4. #import <CommonCrypto/CommonCrypto.h>
  5.  
  6. @implementation TestObj
  7. int main()
  8. {
  9.  
  10. NSLog(@"%@",[self hmac:@"20100508" withKey: @"INBLUEwJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"]);
  11. return 0;
  12. }
  13.  
  14.  
  15. - (NSString *)hmac:(NSString *)plaintext withKey:(NSString *)key
  16. {
  17. const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding];
  18. const char *cData = [plaintext cStringUsingEncoding:NSASCIIStringEncoding];
  19. unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
  20. CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
  21. NSData *HMACData = [NSData dataWithBytes:cHMAC length:sizeof(cHMAC)];
  22. const unsigned char *buffer = (const unsigned char *)[HMACData bytes];
  23. NSMutableString *HMAC = [NSMutableString stringWithCapacity:HMACData.length * 2];
  24. for (int i = 0; i < HMACData.length; ++i){
  25. [HMAC appendFormat:@"%02x", buffer[i]];
  26. }
  27.  
  28. return HMAC;
  29. }
  30. @end
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.m:4:38: fatal error: CommonCrypto/CommonCrypto.h: No such file or directory
 #import <CommonCrypto/CommonCrypto.h>
                                      ^
compilation terminated.
stdout
Standard output is empty