开发者

iPhone: convert string using HMAC-SHA1

开发者 https://www.devze.com 2022-12-25 04:20 出处:网络
i want to generate HMAC-SHA1 of NSString type variable. I see the post but this method give me error in CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cDa开发者_高级运维ta), cHMAC);

i want to generate HMAC-SHA1 of NSString type variable. I see the post but this method give me error in CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cDa开发者_高级运维ta), cHMAC);

and

NSString *hash = [HMAC base64Encoding]; line.

Please suggest how can I generate the HMAC-SHA1 of any string.


Have you got this at the top of your source file?

#import <CommonCrypto/CommonHMAC.h>

Regarding the base64 part of your question, this question will show you where to get a base64 encoding library/protocol.


About the base64Encoding problem: This is because NSData does not contains this method by default, you need to extend NSData with that. In this link is explained http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消