本文介绍了Objective-C的样品code为HMAC-SHA1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要生成HMAC-SHA1的目的C.但我没有找到任何工作。我试着用CommonCrypto,使用CCHMAC,但没有作品。我需要生成一个HMAC并生成HOTP号码后显示。

I need to generate HMAC-SHA1 in Objective C. But i didnt find anything that works. I tried with CommonCrypto, using CCHMAC, but didnt works. I need to generate a hmac and after generate HOTP number.

有人在目标C或C任何例如code?

Somebody have any example code in Objective C or C?

推荐答案

下面是如何使用你生成HMAC SHA-256:

Here's how you generate an HMAC using SHA-256:

NSString *key;
NSString *data;

const char *cKey  = [key cStringUsingEncoding:NSASCIIStringEncoding];
const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding];

unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];

CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);

NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC
                                      length:sizeof(cHMAC)];

NSString *hash = [HMAC base64Encoding];

我不知道一个HOTP库,但算法很简单,如果我没有记错。

I'm not aware of an HOTP library, but the algorithm was quite simple, if I recall correctly.

这篇关于Objective-C的样品code为HMAC-SHA1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 15:07