是否有适用于 iPhone 的库来处理 HMAC-SHA-1 编码 [英] Is there a library for iPhone to work with HMAC-SHA-1 encoding
问题描述
对于 Amazon 服务(S3、EC2、SimpleDB)的所有操作,您需要使用 HMAC-SHA-1 签名(http://en.wikipedia.org/wiki/HMAC、http://docs.amazonwebservices.com/AWSFWS/latest/DeveloperGuide/index.html?SummaryOfAuthentication.html).
For all operation with Amazon services(S3, EC2, SimpleDB) You need to sign all resquest with HMAC-SHA-1 Signature(http://en.wikipedia.org/wiki/HMAC , http://docs.amazonwebservices.com/AWSFWS/latest/DeveloperGuide/index.html?SummaryOfAuthentication.html).
我在 asp.net 后端工作,没有问题.问题出在 iPhone 应用程序中.iPhone 开发人员表示无法使用 HMAC-SHA-1 编码,并且他没有实现自己的算法的权利.作为程序员,我无法理解为什么会出现问题.
I'm working under asp.net backend and there is no problems. Problem is in the iPhone application. iPhone developer says that there is no way to use HMAC-SHA-1 encoding, and he have no rigths to implement his own algorithm. As programmer I cannot understand why there can be a problem.
所以我也想知道 iPhone 开发者是对的吗?
So I want too know is iPhone developer right?
我从来没有为 iPhone 编码过,所以我什至不知道在哪里搜索这样的信息.
推荐答案
CommonCrypto 可以解决问题.
CommonCrypto does the trick.
#import <CommonCrypto/CommonHMAC.h>
然后
/*
inputs:
NSData *keyData;
NSData *clearTextData
*/
uint8_t digest[CC_SHA1_DIGEST_LENGTH] = {0};
CCHmacContext hmacContext;
CCHmacInit(&hmacContext, kCCHmacAlgSHA1, keyData.bytes, keyData.length);
CCHmacUpdate(&hmacContext, clearTextData.bytes, clearTextData.length);
CCHmacFinal(&hmacContext, digest);
NSData *out = [NSData dataWithBytes:digest length:CC_SHA1_DIGEST_LENGTH];
这篇关于是否有适用于 iPhone 的库来处理 HMAC-SHA-1 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!