我正在做HMAC-SHA256編碼。試過但沒有找到任何解決方案。CCHmac上的EXC_BAD_ACCESS
#include <CommonCrypto/CommonHMAC.h>
- (NSString *)hmacWithKey:(NSString *)key andData:(NSString *)data
{
const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding];
const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding];
unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
///////////////////////////////////////////////////////////////
////but on below line of code i am getting EXC_BAD_ACCESS//////
///////////////////////////////////////////////////////////////
CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
//////////////////////////////////////////////
NSData *out = [NSData dataWithBytes:cHMAC length:CC_SHA256_DIGEST_LENGTH];
// description converts to hex but puts <> around it and spaces every 4 bytes
NSString *hash = [out description];
hash = [hash stringByReplacingOccurrencesOfString:@" " withString:@""];
hash = [hash stringByReplacingOccurrencesOfString:@"<" withString:@""];
hash = [hash stringByReplacingOccurrencesOfString:@">" withString:@""];
// hash is now a string with just the 40char hash value in it
NSLog(@"%@",hash);
return hash;
}
請告訴我什麼是錯的,我在這裏做。 謝謝
什麼是在調試器中顯示的錯誤? –
它什麼也沒有顯示。不是一個單詞,只是在此行上顯示EXS_BAD_ACCESS –
不要命名字符串變量和參數「data」,這隻會使程序難以理解。 – zaph