Created
December 3, 2013 06:39
-
-
Save eiel/7764850 to your computer and use it in GitHub Desktop.
以下を参考にコピペしただけ HMAC-sha1 hexdigest http://stackoverflow.com/questions/756492/objective-c-sample-code-for-hmac-sha1
http://stackoverflow.com/questions/735714/iphone-and-hmac-sha-1-encoding ruby のコードとハッシュ値を比較して確認した。
http://ruby-doc.org/stdlib-1.9.3/libdoc/digest/rdoc/Digest/HMAC.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <CommonCrypto/CommonDigest.h> | |
#import <CommonCrypto/CommonHMAC.h> | |
+ (NSString*)hmacsha1Hexdigest:(NSString*)data key:(NSString*)key | |
{ | |
const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; | |
const char *cData = [data cStringUsingEncoding:NSUTF8StringEncoding]; | |
uint8_t digest[CC_SHA1_DIGEST_LENGTH] = {0}; | |
CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), digest); | |
NSData *out = [NSData dataWithBytes:digest length:CC_SHA1_DIGEST_LENGTH]; | |
NSString *hash = [out description]; | |
hash = [hash stringByReplacingOccurrencesOfString:@" " withString:@""]; | |
hash = [hash stringByReplacingOccurrencesOfString:@"<" withString:@""]; | |
hash = [hash stringByReplacingOccurrencesOfString:@">" withString:@""]; | |
return hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment