snej@0
|
1 |
//
|
snej@0
|
2 |
// MYKey.h
|
snej@0
|
3 |
// MYCrypto
|
snej@0
|
4 |
//
|
snej@0
|
5 |
// Created by Jens Alfke on 3/30/09.
|
snej@0
|
6 |
// Copyright 2009 Jens Alfke. All rights reserved.
|
snej@0
|
7 |
//
|
snej@0
|
8 |
|
snej@0
|
9 |
#import "MYKeychainItem.h"
|
snej@0
|
10 |
|
snej@0
|
11 |
|
snej@1
|
12 |
@protocol MYEncryption <NSObject>
|
snej@0
|
13 |
|
snej@1
|
14 |
/** Encrypts data using this key, returning the raw encrypted result. */
|
snej@1
|
15 |
- (NSData*) encryptData: (NSData*)data;
|
snej@1
|
16 |
|
snej@1
|
17 |
@end
|
snej@1
|
18 |
|
snej@1
|
19 |
@protocol MYDecryption <NSObject>
|
snej@1
|
20 |
|
snej@1
|
21 |
/** Decrypts data using this key, returning the original data. */
|
snej@1
|
22 |
- (NSData*) decryptData: (NSData*)data;
|
snej@1
|
23 |
|
snej@1
|
24 |
@end
|
snej@1
|
25 |
|
snej@1
|
26 |
|
snej@1
|
27 |
|
snej@1
|
28 |
/** Abstract superclass for keys.
|
snej@1
|
29 |
Concrete subclasses are MYSymmetricKey and MYPublicKey. */
|
snej@0
|
30 |
@interface MYKey : MYKeychainItem
|
snej@2
|
31 |
{ }
|
snej@0
|
32 |
|
jens@17
|
33 |
/** Creates a key from encoded data (but does not add it to any keychain.) */
|
jens@17
|
34 |
- (id) initWithKeyData: (NSData*)data;
|
jens@17
|
35 |
|
snej@1
|
36 |
/** The key's raw data. */
|
snej@0
|
37 |
@property (readonly) NSData *keyData;
|
snej@0
|
38 |
|
snej@0
|
39 |
/** The user-visible name (kSecKeyPrintName) associated with this key in the Keychain.
|
snej@0
|
40 |
The user can edit this, so don't expect it to be immutable. */
|
snej@0
|
41 |
@property (copy) NSString *name;
|
snej@0
|
42 |
|
snej@0
|
43 |
/** An application-specific string (kSecKeyAlias) associated with this key in the Keychain.
|
snej@0
|
44 |
Not visible to or editable by the user.
|
snej@0
|
45 |
If you own this key, you can store any associated metadata you like here, although be aware
|
snej@0
|
46 |
that it can be read and modified by any other app that can access this key. */
|
snej@0
|
47 |
@property (copy) NSString *alias;
|
snej@0
|
48 |
|
snej@2
|
49 |
|
snej@2
|
50 |
/** @name Mac-Only
|
snej@2
|
51 |
* Functionality not available on iPhone.
|
snej@2
|
52 |
*/
|
snej@2
|
53 |
//@{
|
snej@0
|
54 |
#if !TARGET_OS_IPHONE
|
snej@2
|
55 |
|
snej@0
|
56 |
/** The user-visible comment (kSecKeyApplicationTag) associated with this key in the Keychain.
|
snej@2
|
57 |
The user can edit this, so don't expect it to be immutable. */
|
snej@0
|
58 |
@property (copy) NSString *comment;
|
snej@2
|
59 |
|
snej@0
|
60 |
#endif
|
snej@2
|
61 |
//@}
|
snej@0
|
62 |
|
snej@0
|
63 |
|
snej@2
|
64 |
/** @name Expert
|
snej@2
|
65 |
* Advanced methods.
|
snej@2
|
66 |
*/
|
snej@2
|
67 |
//@{
|
snej@0
|
68 |
|
snej@1
|
69 |
/** Creates a MYKey object for an existing Keychain key reference.
|
snej@1
|
70 |
This is abstract -- must be called on a MYSymmetricKey or MYPublicKey, as appropriate. */
|
snej@1
|
71 |
- (id) initWithKeyRef: (SecKeyRef)keyRef;
|
snej@1
|
72 |
|
snej@1
|
73 |
/** The Keychain object reference for this key. */
|
snej@1
|
74 |
@property (readonly) SecKeyRef keyRef;
|
snej@1
|
75 |
|
snej@1
|
76 |
#if !TARGET_OS_IPHONE
|
snej@1
|
77 |
/** The underlying CSSM_KEY structure; used with low-level crypto APIs. */
|
snej@1
|
78 |
@property (readonly) const struct cssm_key* cssmKey;
|
snej@1
|
79 |
|
snej@2
|
80 |
/** The underlying CSSM_CSP_HANDLE structure; used with low-level crypto APIs. */
|
snej@2
|
81 |
@property (readonly) intptr_t /*CSSM_CSP_HANDLE*/ cssmCSPHandle;
|
snej@2
|
82 |
|
snej@13
|
83 |
@property (readonly) CSSM_ALGORITHMS cssmAlgorithm;
|
snej@13
|
84 |
|
snej@2
|
85 |
/** Gets CSSM authorization credentials for a specified operation, such as
|
snej@2
|
86 |
CSSM_ACL_AUTHORIZATION_ENCRYPT. This pointer is necessary for creating some CSSM operation
|
snej@2
|
87 |
contexts.
|
snej@2
|
88 |
@param operation The type of operation you are going to perform (see the enum values in
|
snej@2
|
89 |
cssmType.h.)
|
snej@2
|
90 |
@param type Specifies whether the operation should be allowed to present a UI. You'll usually
|
snej@2
|
91 |
want to pass kSecCredentialTypeDefault.
|
snej@2
|
92 |
@param outError Will be set to point to an NSError on failure, or nil on success.
|
snej@2
|
93 |
Pass nil if you don't care about the specific error.
|
snej@2
|
94 |
@return The access credentials, or NULL on failure.
|
snej@2
|
95 |
This pointer is valid for as long as you have a reference
|
snej@2
|
96 |
to the key object. Do not free or delete it. */
|
snej@2
|
97 |
- (const CSSM_ACCESS_CREDENTIALS*) cssmCredentialsForOperation: (CSSM_ACL_AUTHORIZATION_TAG)operation
|
snej@2
|
98 |
type: (SecCredentialType)type
|
snej@2
|
99 |
error: (NSError**)outError;
|
snej@2
|
100 |
|
snej@1
|
101 |
#endif
|
snej@2
|
102 |
//@}
|
snej@0
|
103 |
|
snej@0
|
104 |
@end
|