MYPublicKey.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.
snej@0
     1
//
snej@0
     2
//  MYPublicKey.h
snej@0
     3
//  MYCrypto
snej@0
     4
//
snej@0
     5
//  Created by Jens Alfke on 3/25/09.
snej@0
     6
//  Copyright 2009 Jens Alfke. All rights reserved.
snej@0
     7
//
snej@0
     8
snej@0
     9
#import "MYKey.h"
snej@0
    10
@class MYSHA1Digest;
snej@0
    11
snej@0
    12
#if !TARGET_OS_IPHONE
snej@0
    13
#import <Security/SecKey.h>
snej@0
    14
#endif
snej@0
    15
snej@0
    16
snej@1
    17
/** A public key, which can be used for encrypting data and verifying signatures.
snej@3
    18
    MYPublicKeys are created as part of generating a key-pair, 
snej@3
    19
    or by being imported from data into a MYKeychain. */
snej@0
    20
@interface MYPublicKey : MYKey <MYEncryption>
snej@0
    21
{
snej@1
    22
    @private
snej@0
    23
    MYSHA1Digest *_digest;
snej@0
    24
}
snej@0
    25
snej@0
    26
/** The public key's SHA-1 digest. This is a convenient short (20-byte) identifier for the key. */
snej@0
    27
@property (readonly) MYSHA1Digest *publicKeyDigest;
snej@0
    28
snej@0
    29
/** Encrypts a short piece of data using this key, returning the raw encrypted result.
snej@1
    30
    An RSA key can encrypt only blocks smaller than its own key size; this
snej@0
    31
    method will fail and return nil if the data is too long.
snej@0
    32
    RSA encryption is also much slower than regular symmetric-key encryption, so the correct
snej@0
    33
    way to encrypt a large block of data using a public key is to first generate a random
snej@0
    34
    symmetric key, called the "session key" (using a Cryptor), encrypt that session key with the 
snej@0
    35
    public key, and then encrypt your data with the session key. Send the encrypted session key
snej@0
    36
    and the encrypted data. */
snej@0
    37
- (NSData*) encryptData: (NSData*)data;
snej@0
    38
snej@0
    39
/** Verifies the signature of a block of data. If the result is YES, you can be assured that
snej@1
    40
    the signature was generated from the data by using this key's matching private key.
snej@0
    41
    If the result is NO, something is wrong: either the data or the signature was modified,
snej@1
    42
    or the signature was generated by a different private key.
snej@1
    43
    (What's actually verified using RSA is the SHA-256 digest of the data.) */
snej@0
    44
- (BOOL) verifySignature: (NSData*)signature ofData: (NSData*)data;
snej@0
    45
    
snej@0
    46
@end