xcode ios HMAC SHA 256散列 [英] xcode ios HMAC SHA 256 hashing
本文介绍了xcode ios HMAC SHA 256散列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我想知道如何在ios上做一个hmacshad256哈希,因为这是我为wcf服务api做的哈希。我一直在试图寻找一些信息,但通常只是最终得到一个SHA-256哈希。
So I'm trying to figure out how to do a hmacshad256 hash on ios as that's the hash I did for the wcf service api I made. I've been trying to look for some info about it but would usually just end up getting a SHA-256 hash.
这是我唯一的参考资料:
This is the only reference I have:
我不知道这是唯一的方法(导入一个java hmac类)
And I'm not sure if that's the only way to do it (importing a java hmac class)
任何帮助赞赏。
谢谢!
推荐答案
NSString * parameters = @"string to hash"
NSString *salt = @"saltStringHere";
NSData *saltData = [salt dataUsingEncoding:NSUTF8StringEncoding];
NSData *paramData = [parameters dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData* hash = [NSMutableData dataWithLength:CC_SHA256_DIGEST_LENGTH ];
CCHmac(kCCHmacAlgSHA256, saltData.bytes, saltData.length, paramData.bytes, paramData.length, hash.mutableBytes);
NSString *base64Hash = [hash base64Encoding];
以及
#import <CommonCrypto/CommonHMAC.h>
由于 base64Encoding
在iOS 7.0中已弃用,最后一行应为:
Since base64Encoding
is deprecated from iOS 7.0, the last line should be:
NSString *base64Hash = [hash base64EncodedStringWithOptions:0];
这篇关于xcode ios HMAC SHA 256散列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文