Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: SecKeyRef object without KeyChain
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SecKeyRef object without KeyChain



Hi
    Thanks to all. I have a RSA public key at runtime in NSData(bytes)
and need to encrypt my data using the Key.
If i dont have the PublicKey as certificate fromat  OR dont want to
add in KeyChain what is the other way i can use the Key value to
Encrypt Data.

The below is the code i used
PublicKey is the NSdata having the key


  [queryPublicKey setObject:(id)kSecClassKey forKey:(id)kSecClass];
        [queryPublicKey setObject:PublicKey forKey:(id)kSecAttrApplicationTag];
        [queryPublicKey setObject:(id)kSecAttrKeyTypeRSA
forKey:(id)kSecAttrKeyType];
		[queryPublicKey setObject:[NSNumber numberWithInt:1024]
forKey:(id)kSecAttrKeySizeInBits];
        [queryPublicKey setObject:[NSNumber numberWithBool:YES]
forKey:(id)kSecAttrIsPermanent];


		resultCode = SecItemAdd((CFDictionaryRef)queryPublicKey, (CFTypeRef
*)&keypersistentref);
        NSLog(@"Add PublicKey: result code: %d", resultCode);
		resultCode = SecItemCopyMatching((CFDictionaryRef)queryPublicKey,
(CFTypeRef *)&publicKeyReference);
		NSLog(@"Add PublicKey: result code: %d", resultCode);


        [queryPublicKey release];
    }


    return publicKeyReference;

Even though the status code is success , the publicKeyReference object
is Null always , what is mistake i have done ?

Thanks for the Help

Regards
Bose


On Thu, Oct 1, 2009 at 4:44 AM, Wim Lewis <email@hidden> wrote:
>
> On Sep 30, 2009, at 12:19 PM, Ian Cely wrote:
>>
>> You could use the openssl library. It provides all the api you need for
>> doing RSA cryptography (including reading and generating keys) and it is
>> publicly available on Mac OS. If you need code samples "Secure Programming
>> Cookbook for C and C++" from O'Reilly has a good solution.
>
> In addition to OpenSSL, Apple provides the CDSA library (in
> Security.framework). If what you have are raw modulus+exponent values,
> you'll need to put them into a format such as PKCS#1 or X.509, but then you
> can create a CSSM_KEY from that and do the usual crypto operations.
>
> One advantage of using CDSA is that many of Apple's Security and Keychain
> objects are wrappers around their corresponding CDSA objects, and have
> methods to get the CDSA handle from the Sec*Ref, so it's possible to write
> code that can use either a raw key or a keychain item.
>
> Apple has very little documentation on the CDSA/CSSM API, but you can
> download the specification for it from The Open Group. Looking at published
> examples like Jens Alfke's or Wade Tregaskis' is very helpful. (If you can
> use them instead of writing your own code, even better!)
>
>
> On Sep 30, 2009, at 9:14 AM, Conrad Sauerwald wrote:
>>
>> The APIs you'd need for dealing with raw RSA keys are not public, because
>> there are supposed to be a generic APIs for all types of keys.  Until then
>> your best chance is to use X.509 certificates.
>
> I haven't tried, but as I mentioned on cocoa-dev I believe it's possible to
> use SecKeychainItemImport() to parse bare keys (not certificates) in various
> formats and get a SecKeyRef.
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Apple-cdsa mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Apple-cdsa mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >SecKeyRef object without KeyChain (From: bosco fdo <email@hidden>)
 >Re: SecKeyRef object without KeyChain (From: Ian Cely <email@hidden>)
 >Re: SecKeyRef object without KeyChain (From: Wim Lewis <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.