MYKey.h
author Jens Alfke <jens@mooseyard.com>
Thu Jun 04 18:36:30 2009 -0700 (2009-06-04)
changeset 19 f6c91b9da05b
parent 13 6fd9177eb6da
child 23 39fec79de6e8
permissions -rw-r--r--
Whew! MYParsedCertificate can now generate certs from scratch. Also added improvements and fixes to the BER/DER codecs.
     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 /** Creates a key from encoded data (but does not add it to any keychain.) */
    34 - (id) initWithKeyData: (NSData*)data;
    35 
    36 /** The key's raw data. */
    37 @property (readonly) NSData *keyData;
    38 
    39 /** The user-visible name (kSecKeyPrintName) associated with this key in the Keychain.
    40     The user can edit this, so don't expect it to be immutable. */
    41 @property (copy) NSString *name;
    42 
    43 /** An application-specific string (kSecKeyAlias) associated with this key in the Keychain.
    44     Not visible to or editable by the user.
    45     If you own this key, you can store any associated metadata you like here, although be aware
    46     that it can be read and modified by any other app that can access this key. */
    47 @property (copy) NSString *alias;
    48 
    49 
    50 /** @name Mac-Only
    51  *  Functionality not available on iPhone. 
    52  */
    53 //@{
    54 #if !TARGET_OS_IPHONE
    55 
    56 /** The user-visible comment (kSecKeyApplicationTag) associated with this key in the Keychain.
    57  The user can edit this, so don't expect it to be immutable. */
    58 @property (copy) NSString *comment;
    59 
    60 #endif
    61 //@}
    62 
    63 
    64 /** @name Expert
    65  *  Advanced methods. 
    66  */
    67 //@{
    68 
    69 /** Creates a MYKey object for an existing Keychain key reference.
    70     This is abstract -- must be called on a MYSymmetricKey or MYPublicKey, as appropriate. */
    71 - (id) initWithKeyRef: (SecKeyRef)keyRef;
    72 
    73 /** The Keychain object reference for this key. */
    74 @property (readonly) SecKeyRef keyRef;
    75 
    76 #if !TARGET_OS_IPHONE
    77 /** The underlying CSSM_KEY structure; used with low-level crypto APIs. */
    78 @property (readonly) const struct cssm_key* cssmKey;
    79 
    80 /** The underlying CSSM_CSP_HANDLE structure; used with low-level crypto APIs. */
    81 @property (readonly) intptr_t /*CSSM_CSP_HANDLE*/ cssmCSPHandle;
    82 
    83 @property (readonly) CSSM_ALGORITHMS cssmAlgorithm;
    84 
    85 /** Gets CSSM authorization credentials for a specified operation, such as
    86     CSSM_ACL_AUTHORIZATION_ENCRYPT. This pointer is necessary for creating some CSSM operation
    87     contexts.
    88     @param operation  The type of operation you are going to perform (see the enum values in
    89             cssmType.h.)
    90     @param type  Specifies whether the operation should be allowed to present a UI. You'll usually
    91             want to pass kSecCredentialTypeDefault.
    92     @param outError  Will be set to point to an NSError on failure, or nil on success.
    93             Pass nil if you don't care about the specific error.
    94     @return  The access credentials, or NULL on failure. 
    95             This pointer is valid for as long as you have a reference
    96             to the key object. Do not free or delete it. */
    97 - (const CSSM_ACCESS_CREDENTIALS*) cssmCredentialsForOperation: (CSSM_ACL_AUTHORIZATION_TAG)operation
    98                                                           type: (SecCredentialType)type
    99                                                          error: (NSError**)outError;
   100 
   101 #endif
   102 //@}
   103 
   104 @end