| 1 | /* |
|---|
| 2 | Copyright (c) 2003-2006, Septicus Software All rights reserved. |
|---|
| 3 | |
|---|
| 4 | Redistribution and use in source and binary forms, with or without |
|---|
| 5 | modification, are permitted provided that the following conditions are |
|---|
| 6 | met: |
|---|
| 7 | |
|---|
| 8 | * Redistributions of source code must retain the above copyright |
|---|
| 9 | notice, this list of conditions and the following disclaimer. |
|---|
| 10 | * Redistributions in binary form must reproduce the above copyright |
|---|
| 11 | notice, this list of conditions and the following disclaimer in the |
|---|
| 12 | documentation and/or other materials provided with the distribution. |
|---|
| 13 | * Neither the name of Septicus Software nor the names of its contributors |
|---|
| 14 | may be used to endorse or promote products derived from this software |
|---|
| 15 | without specific prior written permission. |
|---|
| 16 | |
|---|
| 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
|---|
| 18 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|---|
| 19 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
|---|
| 20 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
|---|
| 21 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|---|
| 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|---|
| 23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|---|
| 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|---|
| 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|---|
| 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|---|
| 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 28 | */ |
|---|
| 29 | // |
|---|
| 30 | // SSCrypto.h |
|---|
| 31 | // |
|---|
| 32 | // Created by Ed Silva on Sat May 31 2003. |
|---|
| 33 | // Copyright (c) 2003-2006 Septicus Software. All rights reserved. |
|---|
| 34 | // |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | #import <Foundation/Foundation.h> |
|---|
| 38 | #import <openssl/evp.h> |
|---|
| 39 | #import <openssl/rand.h> |
|---|
| 40 | #import <openssl/rsa.h> |
|---|
| 41 | #import <openssl/engine.h> |
|---|
| 42 | #import <openssl/sha.h> |
|---|
| 43 | #import <openssl/pem.h> |
|---|
| 44 | #import <openssl/bio.h> |
|---|
| 45 | #import <openssl/err.h> |
|---|
| 46 | #import <openssl/ssl.h> |
|---|
| 47 | |
|---|
| 48 | @interface NSData (HexDump) |
|---|
| 49 | - (NSString *)encodeBase64; |
|---|
| 50 | - (NSString *)encodeBase64WithNewlines:(BOOL)encodeWithNewlines; |
|---|
| 51 | - (NSData *)decodeBase64; |
|---|
| 52 | - (NSData *)decodeBase64WithNewLines:(BOOL)decodeWithNewLines; |
|---|
| 53 | - (NSString *)hexval; |
|---|
| 54 | - (NSString *)hexdump; |
|---|
| 55 | @end |
|---|
| 56 | |
|---|
| 57 | @interface SSCrypto : NSObject |
|---|
| 58 | { |
|---|
| 59 | NSData *symmetricKey; |
|---|
| 60 | NSData *cipherText; |
|---|
| 61 | NSData *clearText; |
|---|
| 62 | NSData *publicKey; |
|---|
| 63 | NSData *privateKey; |
|---|
| 64 | |
|---|
| 65 | BOOL isSymmetric; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | - (id)init; |
|---|
| 69 | - (id)initWithSymmetricKey:(NSData *)k; |
|---|
| 70 | - (id)initWithPublicKey:(NSData *)pub; |
|---|
| 71 | - (id)initWithPrivateKey:(NSData *)priv; |
|---|
| 72 | - (id)initWithPublicKey:(NSData *)pub privateKey:(NSData *)priv; |
|---|
| 73 | |
|---|
| 74 | - (BOOL)isSymmetric; |
|---|
| 75 | - (void)setIsSymmetric:(BOOL)flag; |
|---|
| 76 | |
|---|
| 77 | - (NSData *)symmetricKey; |
|---|
| 78 | - (void)setSymmetricKey:(NSData *)k; |
|---|
| 79 | |
|---|
| 80 | - (NSData *)publicKey; |
|---|
| 81 | - (void)setPublicKey:(NSData *)k; |
|---|
| 82 | |
|---|
| 83 | - (NSData *)privateKey; |
|---|
| 84 | - (void)setPrivateKey:(NSData *)k; |
|---|
| 85 | |
|---|
| 86 | - (NSData *)clearTextAsData; |
|---|
| 87 | - (NSString *)clearTextAsString; |
|---|
| 88 | - (void)setClearTextWithData:(NSData *)c; |
|---|
| 89 | - (void)setClearTextWithString:(NSString *)c; |
|---|
| 90 | |
|---|
| 91 | - (NSData *)cipherTextAsData; |
|---|
| 92 | - (NSString *)cipherTextAsString; |
|---|
| 93 | - (void)setCipherText:(NSData *)c; |
|---|
| 94 | |
|---|
| 95 | - (NSData *)decrypt; |
|---|
| 96 | - (NSData *)decrypt:(NSString *)cipherName; |
|---|
| 97 | |
|---|
| 98 | - (NSData *)verify; |
|---|
| 99 | |
|---|
| 100 | - (NSData *)encrypt; |
|---|
| 101 | - (NSData *)encrypt:(NSString *)cipherName; |
|---|
| 102 | |
|---|
| 103 | - (NSData *)sign; |
|---|
| 104 | |
|---|
| 105 | - (NSData *)digest:(NSString *)digestName; |
|---|
| 106 | |
|---|
| 107 | + (NSData *)generateRSAPrivateKeyWithLength:(int)length; |
|---|
| 108 | + (NSData *)generateRSAPublicKeyFromPrivateKey:(NSData *)privateKey; |
|---|
| 109 | + (NSData *)getKeyDataWithLength:(int)length; |
|---|
| 110 | + (NSData *)getSHA1ForData:(NSData *)d; |
|---|
| 111 | |
|---|
| 112 | @end |
|---|