HMAC-SHA1 구현

Objective-C 2011. 3. 3. 23:37



OAuth 인증과정에서 사용하는 HMAC-SHA1를 카테고리를 사용하여 구현하는 예제이다.

@interface NSData (ATOAuth) 
- (NSData*)dataByHmacSHA1EncryptingWithKey:(NSData*)key;
@end


#import "NSData+EOUtil.h"
#include <commoncrypto/commonhmac.h>

@implementation NSData (ATOAuth)

- (NSData*)dataByHmacSHA1EncryptingWithKey:(NSData*)key
{   
    void* buffer = malloc(CC_SHA1_DIGEST_LENGTH);
    CCHmac(kCCHmacAlgSHA1, [key bytes], [key length], [self bytes], [self length], buffer);
    return [NSData dataWithBytesNoCopy:buffer length:CC_SHA1_DIGEST_LENGTH freeWhenDone:YES];
}
@end
 



'Objective-C' 카테고리의 다른 글

Objective-C 문자열 조작 메서드  (0) 2011.04.29
다중인자를 갖는 PerformSelector 메시지  (0) 2011.03.23
Protocol 과 Category  (0) 2011.03.22
Objective-C 훑어보기  (2) 2011.03.20
[Cocoa] Cocoa Design Pattern  (0) 2011.03.20
HMAC-SHA1 구현  (0) 2011.03.03