sha1加密
#import <CommonCrypto/CommonHMAC.h>
- (NSString *)getSignStr {
NSString *kApiKey=@"abcdefg";
NSString *kApiSecret=@"gfedcba";
int valid_durtion = 100;
long int current_time = [[NSDate date] timeIntervalSince1970];
long int expire_time = current_time + valid_durtion;
long random = labs(arc4random() % 100000000000);
NSString* str = [NSString stringWithFormat:@"a=%@&b=%ld&c=%ld&d=%ld", kApiKey, expire_time, current_time, random];
const char *cKey = [kApiSecret cStringUsingEncoding:NSUTF8StringEncoding];
const char *cData = [str cStringUsingEncoding:NSUTF8StringEncoding];
char cHMAC[CC_SHA1_DIGEST_LENGTH];
CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)];
NSData* sign_raw_data = [str dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData* data = [[NSMutableData alloc] initWithData:HMAC];
[data appendData:sign_raw_data];
NSString* sign = [data base64EncodedStringWithOptions:0];
return sign;
}