【问题标题】:iOS 9 : SecItemCopyMatching returns successful status code but key is niliOS 9:SecItemCopyMatching 返回成功状态码,但键为 nil
【发布时间】:2015-08-19 13:02:32
【问题描述】:

我正在尝试使用SecItemAdd 将私钥导入钥匙串,方法返回OSStatus 0,但是当我尝试使用SecItemCopyMatch 从钥匙串中检索该钥匙时,它返回零数据但OSStatus 为0 表示成功

请参考苹果开发者论坛link

【问题讨论】:

  • 得到相同的结果,你现在有什么成功的解决方案吗?
  • No..等待iOS9公开发布。
  • 如果您尽快需要它,您可以尝试使用此解决方案在您的代码中进行快速注入 - stackoverflow.com/questions/31549059/…
  • 它对你有用吗?

标签: xcode rsa keychain ios9


【解决方案1】:

由于格式错误的公钥引用https://forums.developer.apple.com/thread/15129而发生错误

如果您使用基本编码规则库,这就是解决方案。

要修复您的公钥,您需要在模数数据之前插入零字节。 https://github.com/StCredZero/SCZ-BasicEncodingRules-iOS/issues/6#issuecomment-136601437

附:对我来说,修复很简单:

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

【讨论】:

  • 没有我的问题是导入私钥而不是公钥...我没有尝试导入公钥
  • 你只是救了我的命,非常感谢,这个简单的解决方案怎么能成功......
【解决方案2】:

谢谢!你是我的英雄!

就我而言。

  • 之前

    NSData *modBits = [[NSData alloc] initWithBase64EncodedString:mod options:NSDataBase64DecodingIgnoreUnknownCharacters];
    
  • 之后

    const char fixByte = 0;
    NSMutableData * modBits = [NSMutableData dataWithBytes:&fixByte length:1];
    
    NSData *tmpmodBits = [[NSData alloc] initWithBase64EncodedString:mod options:NSDataBase64DecodingIgnoreUnknownCharacters];
    
    [modBits appendData:tmpmodBits];
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    • 2022-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多