iOSKit 1.0
iOS Developer Convenience Toolkit
/Users/Matthew/iOSDev/iOSKit/Framework/trunk/iOSKit/SSCrypto.h
00001 /*
00002  Copyright (c) 2003-2006, Septicus Software All rights reserved.
00003  
00004  Redistribution and use in source and binary forms, with or without
00005  modification, are permitted provided that the following conditions are
00006  met:
00007  
00008  * Redistributions of source code must retain the above copyright
00009  notice, this list of conditions and the following disclaimer. 
00010  * Redistributions in binary form must reproduce the above copyright
00011  notice, this list of conditions and the following disclaimer in the
00012  documentation and/or other materials provided with the distribution. 
00013  * Neither the name of Septicus Software nor the names of its contributors
00014  may be used to endorse or promote products derived from this software
00015  without specific prior written permission.
00016  
00017  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00018  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00019  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00020  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00021  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00022  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00023  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00024  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00025  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00026  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00027  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028 */
00029 //
00030 //  SSCrypto.h
00031 //
00032 //  Created by Ed Silva on Sat May 31 2003.
00033 //  Copyright (c) 2003-2006 Septicus Software. All rights reserved.
00034 //
00035 
00036 
00037 #import <Foundation/Foundation.h>
00038 #import <openssl/evp.h>
00039 #import <openssl/rand.h>
00040 #import <openssl/rsa.h>
00041 #import <openssl/engine.h>
00042 #import <openssl/sha.h>
00043 #import <openssl/pem.h>
00044 #import <openssl/bio.h>
00045 #import <openssl/err.h>
00046 #import <openssl/ssl.h>
00047 #import <openssl/md5.h>
00048 
00049 @interface NSData (HexDump)
00050 - (NSString *)encodeBase64;
00051 - (NSString *)encodeBase64WithNewlines:(BOOL)encodeWithNewlines;
00052 - (NSData *)decodeBase64;
00053 - (NSData *)decodeBase64WithNewLines:(BOOL)decodeWithNewLines;
00054 - (NSString *)hexval;
00055 - (NSString *)hexdump;
00056 @end
00057 
00058 @interface SSCrypto : NSObject
00059 {
00060     NSData *symmetricKey;
00061     NSData *cipherText;
00062     NSData *clearText;
00063  NSData *publicKey;
00064  NSData *privateKey;
00065  
00066  BOOL isSymmetric;
00067 }
00068 
00069 - (id)init;
00070 - (id)initWithSymmetricKey:(NSData *)k;
00071 - (id)initWithPublicKey:(NSData *)pub;
00072 - (id)initWithPrivateKey:(NSData *)priv;
00073 - (id)initWithPublicKey:(NSData *)pub privateKey:(NSData *)priv;
00074 
00075 - (BOOL)isSymmetric;
00076 - (void)setIsSymmetric:(BOOL)flag;
00077 
00078 - (NSData *)symmetricKey;
00079 - (void)setSymmetricKey:(NSData *)k;
00080 
00081 - (NSData *)publicKey;
00082 - (void)setPublicKey:(NSData *)k;
00083 
00084 - (NSData *)privateKey;
00085 - (void)setPrivateKey:(NSData *)k;
00086 
00087 - (NSData *)clearTextAsData;
00088 - (NSString *)clearTextAsString;
00089 - (void)setClearTextWithData:(NSData *)c;
00090 - (void)setClearTextWithString:(NSString *)c;
00091 
00092 - (NSData *)cipherTextAsData;
00093 - (NSString *)cipherTextAsString;
00094 - (void)setCipherText:(NSData *)c;
00095 
00096 - (void)setCipherTextFromBase64String:(NSString*)s;
00097 - (NSString *)cipherTextAsBase64String;
00098 
00099 - (NSData *)decrypt;
00100 - (NSData *)decrypt:(NSString *)cipherName;
00101 
00102 - (NSData *)verify;
00103 
00104 - (NSData *)encrypt;
00105 - (NSData *)encrypt:(NSString *)cipherName;
00106 - (NSData *)encrypt:(NSString *)cipherName withSalt:(BOOL)salted;
00107 
00108 - (NSData *)sign;
00109 
00110 - (NSData *)digest:(NSString *)digestName;
00111 
00112 + (NSData *)generateRSAPrivateKeyWithLength:(int)length;
00113 + (NSData *)generateRSAPublicKeyFromPrivateKey:(NSData *)privateKey;
00114 + (NSData *)getKeyDataWithLength:(int)length;
00115 + (NSData *)getKeyDataWithLength:(int)length fromPassword:(NSString *)pass withSalt:(NSString *)salt;
00116 + (NSData *)getKeyDataWithLength:(int)length fromPassword:(NSString *)pass withSalt:(NSString *)salt withIterations:(int)count;
00117 + (NSData *)getSHA1ForData:(NSData *)d;
00118 + (NSData *)getMD5ForData:(NSData *)d;
00119 
00120 @end