升级ios9后RSA加密结果是空 问题是SecItemAdd

17 篇文章 0 订阅
4 篇文章 1 订阅

转自:http://blog.csdn.net/ylgwhyh/article/details/49756209


问题描述(csdn上的网友):

ret = SecItemAdd((__bridge CFDictionaryRef) publicKeyDict, (CFTypeRef*)&pubKeyRef);
在iOS8系统下下面的上面这句代码没问题,ret = 0,pubKeyRef的值是:
po pubKeyRef
<SecKeyRef algorithm id: 1, key type: RSAPublicKey, version: 3, block size: 1024 bits, exponent: {hex: 10001, decimal: 65537}, modulus: B5CE747C46781C81488F169C72828B72233E6E3B70525D2CE088665EC1B61F3F5FC7FE96CFB8BFFA699D61D0316ACC8C021A03ABF703C75510990F95008E4A3303ACF424B3E7EFEA001D0499CE00EB293A79B2054D11852E66D81EABF9B714A0013611059810C4CD670B50AC5D2E6B743049A5297AD38690C25BB3BBF95A331D, addr: 0x15e0baa00>

在ios9下,这句返回值ret = 0,但是pubKeyRef得到的值为空。------摘录至:http://bbs.csdn.net/topics/391833626


问题描述:(苹果官方论坛上面网友的描述):

Hi Guys,

Recenlty I have been testing my code in iOS 9 with Xcode 7 Beta 5. In my app, I am using + (SecKeyRef) addPeerPublicKey:(NSString *) peerName withPublicKey:(NSData *) publicKey method to generate public key from exponent and modulus. It turns out that SecKeyRef generate is always nil in iOS 9 but works well in iOS 8. Is it bug for the Xcode 7 Beta 5 or There are several changing that i need to do in order to make it works in iOS 9?

Please help.

Thanks.

Best Regards, 

Chris               摘录至:https://forums.developer.apple.com/thread/15129


解决办法:

原文链接:http://stackoverflow.com/questions/32096304/ios-9-secitemcopymatching-returns-successful-status-code-but-key-is-nil

The bug occurs due to malformed public key referhttps://forums.developer.apple.com/thread/15129

If you use Basic Encoding Rules library here's the solution.

To fix your public key you need to insert nil byte before modulus data.https://github.com/StCredZero/SCZ-BasicEncodingRules-iOS/issues/6#issuecomment-136601437

P.S. For me fix was as simple as:

const char fixByte = 0;
NSMutableData * fixedModule = [NSMutableData dataWithBytes:&fixByte length:1];
[fixedModule appendData:modulusData];
share improve this answer

其他有用的参考资料:https://github.com/StCredZero/SCZ-BasicEncodingRules-iOS/issues/6#issuecomment-136601437

http://bbs.csdn.net/topics/391833626?page=1#post-400541458


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值