简体   繁体   English

OS X上的SecItemAdd不起作用,在iOS上是

[英]SecItemAdd on OS X not working, on iOS is

I have a problem. 我有个问题。 I have working Code for iOS to add a private Key to the Keychain by SecItemAdd. 我有适用于iOS的工作代码,可通过SecItemAdd将私钥添加到钥匙串中。 It works without any error. 它的工作原理没有任何错误。 On OS X with the same attributes and values, it does not work. 在具有相同属性和值的OS X上,它不起作用。 Any ideas, whats the problem. 任何想法,怎么了。 Here is the part of the Code: 这是代码的一部分:

NSData * keyData = ...
NSString * name = @"TestKey"
NSString * keyID = @"TestKey"
const id keys[]     = {
        (__bridge id)(kSecClass),
        (__bridge id)(kSecAttrKeyClass),
        (__bridge id)(kSecAttrLabel),
        (__bridge id)(kSecAttrApplicationLabel),
        (__bridge id)(kSecAttrIsPermanent),
        (__bridge id)(kSecAttrAccessible),
        (__bridge id)(kSecValueData) };
const id values[]   = {
        (__bridge id)(kSecClassKey),
        (__bridge id)(kSecAttrKeyClassPrivate),
        name,
        keyID,
        (id)kCFBooleanTrue,
        (__bridge id)(kSecAttrAccessibleAfterFirstUnlock),
        keyData };
NSMutableDictionary * attributes    = [[NSMutableDictionary alloc] initWithObjects:values forKeys:keys count:ATTR_COUNT(keys)];

CFTypeRef       result;
NSError * error = nil;

OSStatus osStatus = SecItemAdd((__bridge CFDictionaryRef)attributes, &result);

The error is: 错误是:

25303 (errKCNoSuchAttr / errSecNoSuchAttr: / The attribute does not exist.).) 25303(errKCNoSuchAttr / errSecNoSuchAttr:/该属性不存在。)

The Error code specifies The attribute does not exist , it is due to the attribute : kSecAttrKeyClass . 错误代码指定The attribute does not exist ,这是由于属性: kSecAttrKeyClass Try removing this attribute, and use tag names to distinguish the different keys. 尝试删除此属性,并使用标签名称来区分不同的键。 I was also getting similar issue in my code. 我的代码中也遇到了类似的问题。

Which OS X version are you trying to support? 您要支持哪个OS X版本? OS X Keychain Services are different than iOS Keychain Services. OS X钥匙串服务不同于iOS钥匙串服务。 For example, kSecClass is only available as of OS X 10.7, and kSecAttrAccessible 10.9. 例如,kSecClass仅在OS X 10.7和kSecAttrAccessible 10.9起可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM