1 #import <Foundation/Foundation.h>
2 #import "SSCrypto.h"
3
4 int main (int argc, const char * argv[])
5 {
6 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
7
8 SSCrypto *crypto;
9 int n;
10
11 12
13 14
15 16 17
18 NSString *name = @"foo";
19
20 crypto = [[SSCrypto alloc] init];
21 [crypto setClearTextWithString:name];
22
23 NSLog(@"Name: %@", [crypto clearTextAsString]);
24 NSLog(@"SHA1 Digest of Name using digest method: %@", [[crypto digest:@"SHA1"] hexval]);
25
26 NSData *sha1Name = [SSCrypto getSHA1ForData:[name dataUsingEncoding:NSUTF8StringEncoding]];
27 NSLog(@"SHA1 Digest using getSHA1ForData method: %@", [sha1Name hexval]);
28
29 NSLog(@" ");
30 NSLog(@" ");
31 NSLog(@" ");
32
33 [crypto release];
34
35 36
37 38
39 NSData *seedData1 = [SSCrypto getKeyDataWithLength:32];
40 crypto = [[SSCrypto alloc] initWithSymmetricKey:seedData1];
41
42 NSArray *ciphers = [NSArray arrayWithObjects:@"aes256", @"aes128", @"blowfish", @"aes192",
43 @"RC4", @"blowfish", @"RC5", @"des3", @"des", nil];
44
45 NSString *password = @"pumpkin";
46 [crypto setClearTextWithString:password];
47
48 for(n = 0; n < [ciphers count]; n++)
49 {
50 NSData *cipherText = [crypto encrypt:[ciphers objectAtIndex:n]];
51 NSData *clearText = [crypto decrypt:[ciphers objectAtIndex:n]];
52
53 NSLog(@"Original password: %@", password);
54 NSLog(@"Cipher text: '%@' using %@", [cipherText encodeBase64WithNewlines:NO], [ciphers objectAtIndex:n]);
55 NSLog(@"Clear text: '%s' using %@", [clearText bytes], [ciphers objectAtIndex:n]);
56
57 NSLog(@" ");
58 }
59
60 NSLog(@" ");
61 NSLog(@" ");
62
63 [crypto release];
64
65 66
67 68
69 70 71 72 73 74
75 NSData *seedData2 = [SSCrypto getKeyDataWithLength:32];
76 crypto = [[SSCrypto alloc] initWithSymmetricKey:seedData2];
77
78 NSArray *digests = [NSArray arrayWithObjects:@"MD2", @"MD4", @"MD5", @"SHA1", @"RIPEMD160", nil];
79
80 NSString *secret = @"I like cheese";
81 [crypto setClearTextWithString:secret];
82
83 for(n = 0; n < [digests count]; n++)
84 {
85 NSData *digest = [crypto digest:[digests objectAtIndex:n]];
86 NSLog(@"'%@' %@ digest hexdump: %@", [crypto clearTextAsString], [digests objectAtIndex:n], [digest hexval]);
87 }
88
89 NSLog(@" ");
90 NSLog(@" ");
91 NSLog(@" ");
92
93 [crypto release];
94
95 96
97 98
99 100 101 102 103 104 105
106 107 108
109 110 111
112 113 NSData *privateKeyData = [SSCrypto generateRSAPrivateKeyWithLength:2048];
114 NSLog(@"privateKeyData: \n%s", [privateKeyData bytes]);
115 116 NSData *publicKeyData = [SSCrypto generateRSAPublicKeyFromPrivateKey:privateKeyData];
117 NSLog(@"publicKeyData: \n%s", [publicKeyData bytes]);
118
119 120 121 122 123 124
125 126
127 128
129 130 131
132 133 134
135 crypto = [[SSCrypto alloc] initWithPublicKey:publicKeyData privateKey:privateKeyData];
136
137 NSString *secretPhrase = @"The duck quacks at daybreak";
138 [crypto setClearTextWithString:secretPhrase];
139
140 NSData *signedTextData = [crypto sign];
141 NSData *verifiedTextData = [crypto verify];
142
143 NSLog(@"Secret Phrase: %@", secretPhrase);
144 NSLog(@"Signed (Encrypted using private key): %@", [signedTextData encodeBase64]);
145 NSLog(@"Verified (Decrypted using public key): %s", [verifiedTextData bytes]);
146
147 148 149
150 NSLog(@" ");
151 NSLog(@" ");
152 NSLog(@" ");
153
154 [crypto release];
155
156 157
158 159
160 161 162 163 164
165 166 167
168 crypto = [[SSCrypto alloc] initWithPublicKey:publicKeyData privateKey:privateKeyData];
169
170 NSString *topSecret = @"Billy likes Mandy";
171 [crypto setClearTextWithString:topSecret];
172
173 NSData *encryptedTextData = [crypto encrypt];
174 NSData *decryptedTextData = [crypto decrypt];
175
176 NSLog(@"Top Secret: %@", topSecret);
177 NSLog(@"Encrypted: %@", [encryptedTextData encodeBase64]);
178 NSLog(@"Decrypted: %s", [decryptedTextData bytes]);
179
180 181 182
183 NSLog(@" ");
184 NSLog(@" ");
185 NSLog(@" ");
186
187 [crypto release];
188
189 190
191 [pool release];
192 return 0;
193 }
194