2

I have a problem. I have working Code for iOS to add a private Key to the Keychain by SecItemAdd. It works without any error. On OS X with the same attributes and values, it does not work. 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.).)

1
  • For what it's worth, I am finding that SecItemCopyMatching() code that works on iOS to retrieve public key bits does not work on OSX. It always returns 96 bytes, regardless of key size. Commented Aug 5, 2015 at 23:29

2 Answers 2

3

The Error code specifies The attribute does not exist, it is due to the attribute : kSecAttrKeyClass. Try removing this attribute, and use tag names to distinguish the different keys. I was also getting similar issue in my code.

Sign up to request clarification or add additional context in comments.

Comments

1

Which OS X version are you trying to support? OS X Keychain Services are different than iOS Keychain Services. For example, kSecClass is only available as of OS X 10.7, and kSecAttrAccessible 10.9.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.