MYKey.h
changeset 0 0a6527af039b
child 1 60e4cbbb5128
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/MYKey.h	Sat Apr 04 20:42:03 2009 -0700
     1.3 @@ -0,0 +1,78 @@
     1.4 +//
     1.5 +//  MYKey.h
     1.6 +//  MYCrypto
     1.7 +//
     1.8 +//  Created by Jens Alfke on 3/30/09.
     1.9 +//  Copyright 2009 Jens Alfke. All rights reserved.
    1.10 +//
    1.11 +
    1.12 +#import "MYKeychainItem.h"
    1.13 +
    1.14 +#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
    1.15 +typedef CFTypeRef SecExternalItemType;
    1.16 +#endif
    1.17 +
    1.18 +
    1.19 +@interface MYKey : MYKeychainItem
    1.20 +{
    1.21 +    @private
    1.22 +    SecKeyRef _key;
    1.23 +}
    1.24 +
    1.25 +/** Creates a MYKey object for an existing Keychain key reference. */
    1.26 +- (id) initWithKeyRef: (SecKeyRef)keyRef;
    1.27 +
    1.28 +/** Creates a MYKey object from exported key data, but does not add it to any keychain. */
    1.29 +- (id) initWithKeyData: (NSData*)data;
    1.30 +
    1.31 +#if !TARGET_OS_IPHONE
    1.32 +/** Converts the key into a data blob in one of several standard formats, suitable for storing in
    1.33 +    a file or sending over the network.
    1.34 +    @param format  The data format: kSecFormatOpenSSL, kSecFormatSSH, kSecFormatBSAFE or kSecFormatSSHv2.
    1.35 +    @param withPEM  YES if the data should be encoded in PEM format, which converts into short lines
    1.36 +        of printable ASCII characters, suitable for sending in email. */
    1.37 +- (NSData*) exportKeyInFormat: (SecExternalFormat)format withPEM: (BOOL)withPEM;
    1.38 +#endif
    1.39 +
    1.40 +/** The Keychain object reference for this key. */
    1.41 +@property (readonly) SecKeyRef keyRef;
    1.42 +
    1.43 +/** The key's raw data in OpenSSL format. This is the same as calling
    1.44 +    -exportKeyInFormat: kSecFormatOpenSSL withPEM: NO */
    1.45 +@property (readonly) NSData *keyData;
    1.46 +
    1.47 +@property (readonly) SecExternalItemType keyType;
    1.48 +
    1.49 +/** The user-visible name (kSecKeyPrintName) associated with this key in the Keychain.
    1.50 +    The user can edit this, so don't expect it to be immutable. */
    1.51 +@property (copy) NSString *name;
    1.52 +
    1.53 +/** An application-specific string (kSecKeyAlias) associated with this key in the Keychain.
    1.54 +    Not visible to or editable by the user.
    1.55 +    If you own this key, you can store any associated metadata you like here, although be aware
    1.56 +    that it can be read and modified by any other app that can access this key. */
    1.57 +@property (copy) NSString *alias;
    1.58 +
    1.59 +#if !TARGET_OS_IPHONE
    1.60 +/** The user-visible comment (kSecKeyApplicationTag) associated with this key in the Keychain.
    1.61 +    The user can edit this, so don't expect it to be immutable. */
    1.62 +@property (copy) NSString *comment;
    1.63 +#endif
    1.64 +
    1.65 +@end
    1.66 +
    1.67 +
    1.68 +
    1.69 +@protocol MYEncryption <NSObject>
    1.70 +
    1.71 +/** Encrypts data using this key, returning the raw encrypted result. */
    1.72 +- (NSData*) encryptData: (NSData*)data;
    1.73 +
    1.74 +@end
    1.75 +
    1.76 +@protocol MYDecryption <NSObject>
    1.77 +
    1.78 +/** Decrypts data using this key, returning the original data. */
    1.79 +- (NSData*) decryptData: (NSData*)data;
    1.80 +
    1.81 +@end