1
我的代碼如下所示(使用CommonCrypto/CommonHMAC.h):HMAC SHA 384在iOS
- (NSString*) preperingCryptedData: (NSString*) data withKey: (NSString*) key {
NSData* dataToHash = [data dataUsingEncoding:NSUTF8StringEncoding];
NSData* keyData = [key dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"Utility: preperingCryptedData - Data to Crypt: %@ and key %@\n...\n...\n...\n",dataToHash,keyData);
NSMutableData *dataHash = [NSMutableData dataWithLength:CC_SHA384_DIGEST_LENGTH];
CCHmac(kCCHmacAlgSHA384, keyData.bytes, keyData.length, dataToHash.bytes, dataToHash.length, dataHash.mutableBytes);
NSString* readyString = [[NSString alloc] initWithData:dataToHash encoding:NSUTF8StringEncoding];
NSLog(@"Utility: preperingCryptedData call, result :%@\n...\n...\n...\n",readyString);
return readyString;
}
當我使用的代碼:Here我得到了我的字符串解碼,而不關鍵。我究竟做錯了什麼?如何在沒有密鑰的情況下對消息進行編碼?