iOS 加密

Nineth999 2014-08-06 01:40:46
c# 代码:

public static string GetSignature(string url, string key)
{

Uri uri = new Uri(url);

byte[] sequence = ASCIIEncoding.UTF8.GetBytes(HttpUtility.UrlDecode(uri.PathAndQuery));//uri.PathAndQuery请求参数

HMACSHA1 algorithm = new HMACSHA1(Encoding.UTF8.GetBytes(key.ToLower()));

return Convert.ToBase64String(algorithm.ComputeHash(sequence));



怎么 转化为 oc 代码
...全文
231 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Nineth999 2014-08-19
  • 打赏
  • 举报
回复
#import "Base64.h" #include <CommonCrypto/CommonDigest.h> #include <CommonCrypto/CommonHMAC.h> - (NSString *)hmacsha1:(NSString *)data secret:(NSString *)key { const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding]; const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding]; unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH]; CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC); NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)]; NSString *hash = [HMAC base64String]; return hash; } 这个 就是我要的。。。。
Nineth999 2014-08-19
  • 打赏
  • 举报
回复
#import "Base64.h" #include <CommonCrypto/CommonDigest.h> #include <CommonCrypto/CommonHMAC.h> - (NSString *)hmacsha1:(NSString *)data secret:(NSString *)key { const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding]; const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding]; unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH]; CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC); NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)]; NSString *hash = [HMAC base64String]; return hash; }
onunix 2014-08-11
  • 打赏
  • 举报
回复
HMACSHA1是种加密算法,网上可以搜得的。
Bannings 2014-08-11
  • 打赏
  • 举报
回复
引用 4 楼 nineth999 的回复:
[quote=引用 2 楼 ybh37 的回复:] 哈希完了再Base64嘛~ 不知道algorithm.ComputeHash是个啥~
iOS 取哈希值 怎么取 啊 是这样子的 嘛? NSString *test = @"tttttt" test.hash ?[/quote] 是的,直接在对象上hash就行了
咸清 2014-08-11
  • 打赏
  • 举报
回复
引用 4 楼 nineth999 的回复:
[quote=引用 2 楼 ybh37 的回复:] 哈希完了再Base64嘛~ 不知道algorithm.ComputeHash是个啥~
iOS 取哈希值 怎么取 啊 是这样子的 嘛? NSString *test = @"tttttt" test.hash ?[/quote] 估计是类似的算法,algorithm.ComputeHash(sequence) 这个东西我不知道是什么逻辑。
阮小木 2014-08-06
  • 打赏
  • 举报
回复
通讯加密,一般密码直接用MD5,信息用其他的非对称加密算法如rsa
Nineth999 2014-08-06
  • 打赏
  • 举报
回复
引用 2 楼 ybh37 的回复:
哈希完了再Base64嘛~ 不知道algorithm.ComputeHash是个啥~
iOS 取哈希值 怎么取 啊 是这样子的 嘛? NSString *test = @"tttttt" test.hash ?
Bannings 2014-08-06
  • 打赏
  • 举报
回复
确实,HMACSHA1这个类不知道是做什么的,其他的倒可以猜猜。比如uri.PathAndQuery应该是取的是url的最后一部分:?param1=value1¶m2=value2......
咸清 2014-08-06
  • 打赏
  • 举报
回复
哈希完了再Base64嘛~ 不知道algorithm.ComputeHash是个啥~
Nineth999 2014-08-06
  • 打赏
  • 举报
回复
有木有。。。。懂的,,,

29,031

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧