MYKey.h
author snej@snej.local
Sun Apr 19 00:01:41 2009 -0700 (2009-04-19)
changeset 13 6fd9177eb6da
parent 2 8982b8fada63
child 17 90a70925562b
permissions -rw-r--r--
Implemented wrap/unwrap of session key using a key-pair.
     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 #endif
    58 //@}
    59 
    60 
    61 /** @name Expert
    62  *  Advanced methods. 
    63  */
    64 //@{
    65 
    66 /** Creates a MYKey object for an existing Keychain key reference.
    67     This is abstract -- must be called on a MYSymmetricKey or MYPublicKey, as appropriate. */
    68 - (id) initWithKeyRef: (SecKeyRef)keyRef;
    69 
    70 /** The Keychain object reference for this key. */
    71 @property (readonly) SecKeyRef keyRef;
    72 
    73 #if !TARGET_OS_IPHONE
    74 /** The underlying CSSM_KEY structure; used with low-level crypto APIs. */
    75 @property (readonly) const struct cssm_key* cssmKey;
    76 
    77 /** The underlying CSSM_CSP_HANDLE structure; used with low-level crypto APIs. */
    78 @property (readonly) intptr_t /*CSSM_CSP_HANDLE*/ cssmCSPHandle;
    79 
    80 @property (readonly) CSSM_ALGORITHMS cssmAlgorithm;
    81 
    82 /** Gets CSSM authorization credentials for a specified operation, such as
    83     CSSM_ACL_AUTHORIZATION_ENCRYPT. This pointer is necessary for creating some CSSM operation
    84     contexts.
    85     @param operation  The type of operation you are going to perform (see the enum values in
    86             cssmType.h.)
    87     @param type  Specifies whether the operation should be allowed to present a UI. You'll usually
    88             want to pass kSecCredentialTypeDefault.
    89     @param outError  Will be set to point to an NSError on failure, or nil on success.
    90             Pass nil if you don't care about the specific error.
    91     @return  The access credentials, or NULL on failure. 
    92             This pointer is valid for as long as you have a reference
    93             to the key object. Do not free or delete it. */
    94 - (const CSSM_ACCESS_CREDENTIALS*) cssmCredentialsForOperation: (CSSM_ACL_AUTHORIZATION_TAG)operation
    95                                                           type: (SecCredentialType)type
    96                                                          error: (NSError**)outError;
    97 
    98 #endif
    99 //@}
   100 
   101 @end