MYKey.h
author snej@snej.local
Sat Apr 04 20:42:03 2009 -0700 (2009-04-04)
changeset 0 0a6527af039b
child 1 60e4cbbb5128
permissions -rw-r--r--
Initial checkin. Passes tests on Mac and in iPhone simulator.
     1 //
     2 //  MYKey.h
     3 //  MYCrypto
     4 //
     5 //  Created by Jens Alfke on 3/30/09.
     6 //  Copyright 2009 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import "MYKeychainItem.h"
    10 
    11 #if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
    12 typedef CFTypeRef SecExternalItemType;
    13 #endif
    14 
    15 
    16 @interface MYKey : MYKeychainItem
    17 {
    18     @private
    19     SecKeyRef _key;
    20 }
    21 
    22 /** Creates a MYKey object for an existing Keychain key reference. */
    23 - (id) initWithKeyRef: (SecKeyRef)keyRef;
    24 
    25 /** Creates a MYKey object from exported key data, but does not add it to any keychain. */
    26 - (id) initWithKeyData: (NSData*)data;
    27 
    28 #if !TARGET_OS_IPHONE
    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;
    35 #endif
    36 
    37 /** The Keychain object reference for this key. */
    38 @property (readonly) SecKeyRef keyRef;
    39 
    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;
    43 
    44 @property (readonly) SecExternalItemType keyType;
    45 
    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;
    49 
    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;
    55 
    56 #if !TARGET_OS_IPHONE
    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;
    60 #endif
    61 
    62 @end
    63 
    64 
    65 
    66 @protocol MYEncryption <NSObject>
    67 
    68 /** Encrypts data using this key, returning the raw encrypted result. */
    69 - (NSData*) encryptData: (NSData*)data;
    70 
    71 @end
    72 
    73 @protocol MYDecryption <NSObject>
    74 
    75 /** Decrypts data using this key, returning the original data. */
    76 - (NSData*) decryptData: (NSData*)data;
    77 
    78 @end