MYKey.h
author snej@snej.local
Thu Apr 09 22:46:48 2009 -0700 (2009-04-09)
changeset 6 2d7692f9b6b4
parent 1 60e4cbbb5128
child 13 6fd9177eb6da
permissions -rw-r--r--
Updated the README for the 0.1 release.
     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 
    12 @protocol MYEncryption <NSObject>
    13 
    14 /** Encrypts data using this key, returning the raw encrypted result. */
    15 - (NSData*) encryptData: (NSData*)data;
    16 
    17 @end
    18 
    19 @protocol MYDecryption <NSObject>
    20 
    21 /** Decrypts data using this key, returning the original data. */
    22 - (NSData*) decryptData: (NSData*)data;
    23 
    24 @end
    25 
    26 
    27 
    28 /** Abstract superclass for keys.
    29     Concrete subclasses are MYSymmetricKey and MYPublicKey. */
    30 @interface MYKey : MYKeychainItem
    31 { }
    32 
    33 /** The key's raw data. */
    34 @property (readonly) NSData *keyData;
    35 
    36 /** The user-visible name (kSecKeyPrintName) associated with this key in the Keychain.
    37     The user can edit this, so don't expect it to be immutable. */
    38 @property (copy) NSString *name;
    39 
    40 /** An application-specific string (kSecKeyAlias) associated with this key in the Keychain.
    41     Not visible to or editable by the user.
    42     If you own this key, you can store any associated metadata you like here, although be aware
    43     that it can be read and modified by any other app that can access this key. */
    44 @property (copy) NSString *alias;
    45 
    46 
    47 /** @name Mac-Only
    48  *  Functionality not available on iPhone. 
    49  */
    50 //@{
    51 #if !TARGET_OS_IPHONE
    52 
    53 /** The user-visible comment (kSecKeyApplicationTag) associated with this key in the Keychain.
    54  The user can edit this, so don't expect it to be immutable. */
    55 @property (copy) NSString *comment;
    56 
    57 /** Converts the key into a data blob in one of several standard formats, suitable for storing in
    58     a file or sending over the network.
    59     @param format  The data format: kSecFormatOpenSSL, kSecFormatSSH, kSecFormatBSAFE or kSecFormatSSHv2.
    60     @param withPEM  YES if the data should be encoded in PEM format, which converts into short lines
    61         of printable ASCII characters, suitable for sending in email. */
    62 - (NSData*) exportKeyInFormat: (SecExternalFormat)format withPEM: (BOOL)withPEM;
    63 
    64 #endif
    65 //@}
    66 
    67 
    68 /** @name Expert
    69  *  Advanced methods. 
    70  */
    71 //@{
    72 
    73 /** Creates a MYKey object for an existing Keychain key reference.
    74     This is abstract -- must be called on a MYSymmetricKey or MYPublicKey, as appropriate. */
    75 - (id) initWithKeyRef: (SecKeyRef)keyRef;
    76 
    77 /** The Keychain object reference for this key. */
    78 @property (readonly) SecKeyRef keyRef;
    79 
    80 #if !TARGET_OS_IPHONE
    81 /** The underlying CSSM_KEY structure; used with low-level crypto APIs. */
    82 @property (readonly) const struct cssm_key* cssmKey;
    83 
    84 /** The underlying CSSM_CSP_HANDLE structure; used with low-level crypto APIs. */
    85 @property (readonly) intptr_t /*CSSM_CSP_HANDLE*/ cssmCSPHandle;
    86 
    87 /** Gets CSSM authorization credentials for a specified operation, such as
    88     CSSM_ACL_AUTHORIZATION_ENCRYPT. This pointer is necessary for creating some CSSM operation
    89     contexts.
    90     @param operation  The type of operation you are going to perform (see the enum values in
    91             cssmType.h.)
    92     @param type  Specifies whether the operation should be allowed to present a UI. You'll usually
    93             want to pass kSecCredentialTypeDefault.
    94     @param outError  Will be set to point to an NSError on failure, or nil on success.
    95             Pass nil if you don't care about the specific error.
    96     @return  The access credentials, or NULL on failure. 
    97             This pointer is valid for as long as you have a reference
    98             to the key object. Do not free or delete it. */
    99 - (const CSSM_ACCESS_CREDENTIALS*) cssmCredentialsForOperation: (CSSM_ACL_AUTHORIZATION_TAG)operation
   100                                                           type: (SecCredentialType)type
   101                                                          error: (NSError**)outError;
   102 
   103 #endif
   104 //@}
   105 
   106 @end