Initial checkin. Passes tests on Mac and in iPhone simulator.
5 // Created by Jens Alfke on 3/30/09.
6 // Copyright 2009 Jens Alfke. All rights reserved.
9 #import "MYKeychainItem.h"
11 #if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
12 typedef CFTypeRef SecExternalItemType;
16 @interface MYKey : MYKeychainItem
22 /** Creates a MYKey object for an existing Keychain key reference. */
23 - (id) initWithKeyRef: (SecKeyRef)keyRef;
25 /** Creates a MYKey object from exported key data, but does not add it to any keychain. */
26 - (id) initWithKeyData: (NSData*)data;
29 /** Converts the key into a data blob in one of several standard formats, suitable for storing in
30 a file or sending over the network.
31 @param format The data format: kSecFormatOpenSSL, kSecFormatSSH, kSecFormatBSAFE or kSecFormatSSHv2.
32 @param withPEM YES if the data should be encoded in PEM format, which converts into short lines
33 of printable ASCII characters, suitable for sending in email. */
34 - (NSData*) exportKeyInFormat: (SecExternalFormat)format withPEM: (BOOL)withPEM;
37 /** The Keychain object reference for this key. */
38 @property (readonly) SecKeyRef keyRef;
40 /** The key's raw data in OpenSSL format. This is the same as calling
41 -exportKeyInFormat: kSecFormatOpenSSL withPEM: NO */
42 @property (readonly) NSData *keyData;
44 @property (readonly) SecExternalItemType keyType;
46 /** The user-visible name (kSecKeyPrintName) associated with this key in the Keychain.
47 The user can edit this, so don't expect it to be immutable. */
48 @property (copy) NSString *name;
50 /** An application-specific string (kSecKeyAlias) associated with this key in the Keychain.
51 Not visible to or editable by the user.
52 If you own this key, you can store any associated metadata you like here, although be aware
53 that it can be read and modified by any other app that can access this key. */
54 @property (copy) NSString *alias;
57 /** The user-visible comment (kSecKeyApplicationTag) associated with this key in the Keychain.
58 The user can edit this, so don't expect it to be immutable. */
59 @property (copy) NSString *comment;
66 @protocol MYEncryption <NSObject>
68 /** Encrypts data using this key, returning the raw encrypted result. */
69 - (NSData*) encryptData: (NSData*)data;
73 @protocol MYDecryption <NSObject>
75 /** Decrypts data using this key, returning the original data. */
76 - (NSData*) decryptData: (NSData*)data;