├── FBEncrypt ├── FBEncryptAppDelegate.h ├── FBEncryptAppDelegate.m ├── FBEncryptViewController.h ├── FBEncryptViewController.m ├── FBEncryptor-Info.plist ├── FBEncryptor-Prefix.pch ├── en.lproj │ ├── FBEncryptViewController.xib │ ├── InfoPlist.strings │ └── MainWindow.xib └── main.m ├── FBEncryptTests ├── FBEncryptTests.h ├── FBEncryptTests.m ├── FBEncryptorTests-Info.plist ├── FBEncryptorTests-Prefix.pch └── en.lproj │ └── InfoPlist.strings ├── FBEncryptor.xcodeproj └── project.pbxproj ├── FBEncryptorAES.h ├── FBEncryptorAES.m ├── NSData+Base64.h ├── NSData+Base64.m └── README.md /FBEncrypt/FBEncryptAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2011 Five-technology Co.,Ltd. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | #import 24 | 25 | @class FBEncryptViewController; 26 | 27 | @interface FBEncryptAppDelegate : NSObject { 28 | 29 | } 30 | 31 | @property (nonatomic, retain) IBOutlet UIWindow *window; 32 | 33 | @property (nonatomic, retain) IBOutlet FBEncryptViewController *viewController; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /FBEncrypt/FBEncryptAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2011 Five-technology Co.,Ltd. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | #import "FBEncryptAppDelegate.h" 24 | #import "FBEncryptViewController.h" 25 | 26 | @implementation FBEncryptAppDelegate 27 | 28 | 29 | @synthesize window=_window; 30 | @synthesize viewController=_viewController; 31 | 32 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 33 | { 34 | // Override point for customization after application launch. 35 | 36 | self.window.rootViewController = self.viewController; 37 | [self.window makeKeyAndVisible]; 38 | return YES; 39 | } 40 | 41 | - (void)applicationWillResignActive:(UIApplication *)application 42 | { 43 | /* 44 | Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 45 | Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 46 | */ 47 | } 48 | 49 | - (void)applicationDidEnterBackground:(UIApplication *)application 50 | { 51 | /* 52 | Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 53 | If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 54 | */ 55 | } 56 | 57 | - (void)applicationWillEnterForeground:(UIApplication *)application 58 | { 59 | /* 60 | Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 61 | */ 62 | } 63 | 64 | - (void)applicationDidBecomeActive:(UIApplication *)application 65 | { 66 | /* 67 | Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 68 | */ 69 | } 70 | 71 | - (void)applicationWillTerminate:(UIApplication *)application 72 | { 73 | /* 74 | Called when the application is about to terminate. 75 | Save data if appropriate. 76 | See also applicationDidEnterBackground:. 77 | */ 78 | } 79 | 80 | - (void)dealloc 81 | { 82 | [_window release]; 83 | [_viewController release]; 84 | [super dealloc]; 85 | } 86 | 87 | @end 88 | -------------------------------------------------------------------------------- /FBEncrypt/FBEncryptViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2011 Five-technology Co.,Ltd. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | #import 24 | 25 | @interface FBEncryptViewController : UIViewController { 26 | 27 | } 28 | 29 | @property (nonatomic, retain) IBOutlet UITextView* message; 30 | @property (nonatomic, retain) IBOutlet UITextView* encrypted; 31 | @property (nonatomic, retain) IBOutlet UITextView* decrypted; 32 | @property (nonatomic, retain) IBOutlet UITextField* key; 33 | @property (nonatomic, retain) IBOutlet UIScrollView* scrollView; 34 | @property (nonatomic, retain) IBOutlet UISwitch* separateline; 35 | 36 | - (IBAction)encrypt:(id)sender; 37 | - (IBAction)decrypt:(id)sender; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /FBEncrypt/FBEncryptViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2011 Five-technology Co.,Ltd. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | #import "FBEncryptViewController.h" 24 | #import "FBEncryptorAES.h" 25 | 26 | @implementation FBEncryptViewController 27 | 28 | @synthesize message; 29 | @synthesize encrypted; 30 | @synthesize decrypted; 31 | @synthesize key; 32 | @synthesize scrollView; 33 | @synthesize separateline; 34 | 35 | - (void)dealloc 36 | { 37 | [super dealloc]; 38 | } 39 | 40 | - (void)didReceiveMemoryWarning 41 | { 42 | // Releases the view if it doesn't have a superview. 43 | [super didReceiveMemoryWarning]; 44 | 45 | // Release any cached data, images, etc that aren't in use. 46 | } 47 | 48 | #pragma mark - View lifecycle 49 | 50 | // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 51 | - (void)viewDidLoad 52 | { 53 | [super viewDidLoad]; 54 | self.scrollView.contentSize = CGSizeMake(320, 320+640); 55 | } 56 | 57 | - (void)viewDidUnload 58 | { 59 | [super viewDidUnload]; 60 | // Release any retained subviews of the main view. 61 | // e.g. self.myOutlet = nil; 62 | } 63 | 64 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 65 | { 66 | // Return YES for supported orientations 67 | return (interfaceOrientation == UIInterfaceOrientationPortrait); 68 | } 69 | 70 | - (IBAction)encrypt:(id)sender 71 | { 72 | self.encrypted.text = [FBEncryptorAES encryptBase64String:self.message.text 73 | keyString:self.key.text 74 | separateLines:[self.separateline isOn]]; 75 | NSLog(@"encrypted: %@", self.encrypted.text); 76 | } 77 | 78 | - (IBAction)decrypt:(id)sender 79 | { 80 | NSString* msg = [FBEncryptorAES decryptBase64String:self.encrypted.text 81 | keyString:self.key.text]; 82 | 83 | if (msg) { 84 | self.decrypted.text = msg; 85 | NSLog(@"decrypted: %@", msg); 86 | } else { 87 | self.decrypted.text = @"(failed to decrypt)"; 88 | } 89 | 90 | } 91 | 92 | 93 | /* 94 | - (IBAction)exg:(id)sender 95 | { 96 | if (self.ivString == nil || [self.ivString.text length] == 0) { 97 | return; 98 | } 99 | const char* ivPtr = [self.ivString.text cStringUsingEncoding:NSUTF8StringEncoding]; 100 | NSMutableString* str = [NSMutableString string]; 101 | int len = 0; 102 | while (*ivPtr) { 103 | [str appendFormat:@"%02X", *ivPtr]; 104 | len++; 105 | ivPtr++; 106 | } 107 | while (len < 16) { 108 | [str appendString:@"00"]; 109 | len++; 110 | } 111 | self.iv.text = str; 112 | NSLog(@"iv: %@", str); 113 | } 114 | */ 115 | 116 | @end 117 | -------------------------------------------------------------------------------- /FBEncrypt/FBEncryptor-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | jp.5tec.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleShortVersionString 22 | 1.0 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | 1.0 27 | LSRequiresIPhoneOS 28 | 29 | NSMainNibFile 30 | MainWindow 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /FBEncrypt/FBEncryptor-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'FBEncrypt' target in the 'FBEncrypt' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_3_0 8 | #warning "This project uses features only available in iPhone SDK 3.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /FBEncrypt/en.lproj/FBEncryptViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1056 5 | 10J869 6 | 1305 7 | 1038.35 8 | 461.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 300 12 | 13 | 14 | YES 15 | IBProxyObject 16 | IBUIButton 17 | IBUILabel 18 | IBUISwitch 19 | IBUITextField 20 | IBUITextView 21 | IBUIScrollView 22 | IBUIView 23 | 24 | 25 | YES 26 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 27 | 28 | 29 | YES 30 | 31 | YES 32 | 33 | 34 | 35 | 36 | YES 37 | 38 | IBFilesOwner 39 | IBCocoaTouchFramework 40 | 41 | 42 | IBFirstResponder 43 | IBCocoaTouchFramework 44 | 45 | 46 | 47 | 274 48 | 49 | YES 50 | 51 | 52 | 274 53 | 54 | YES 55 | 56 | 57 | 292 58 | {{0, 29}, {320, 77}} 59 | 60 | 61 | 62 | 1 63 | MSAxIDEAA 64 | 65 | YES 66 | YES 67 | IBCocoaTouchFramework 68 | Write text here and touch encrypt button and confirm the encrypted message. 69 | 70 | Helvetica 71 | 17 72 | 16 73 | 74 | 75 | 2 76 | IBCocoaTouchFramework 77 | 78 | 79 | 80 | 81 | 292 82 | {{0, 239}, {320, 81}} 83 | 84 | 85 | 86 | 1 87 | MC45ODgzNjI0NTYgMSAwLjc5NjcyMTA5MwA 88 | 89 | YES 90 | YES 91 | IBCocoaTouchFramework 92 | 93 | 94 | 95 | 2 96 | IBCocoaTouchFramework 97 | 98 | 99 | 100 | 101 | 292 102 | {{6, 117}, {42, 21}} 103 | 104 | 105 | NO 106 | YES 107 | 7 108 | NO 109 | IBCocoaTouchFramework 110 | Key 111 | 112 | 113 | 1 114 | MCAwIDAAA 115 | 116 | 117 | 1 118 | 10 119 | 120 | 121 | 122 | 292 123 | {{10, 158}, {101, 21}} 124 | 125 | 126 | NO 127 | YES 128 | 7 129 | NO 130 | IBCocoaTouchFramework 131 | Separate line 132 | 133 | 134 | 135 | 1 136 | 10 137 | 138 | 139 | 140 | 292 141 | {{10, 2}, {69, 21}} 142 | 143 | 144 | NO 145 | YES 146 | 7 147 | NO 148 | IBCocoaTouchFramework 149 | Message 150 | 151 | 152 | 153 | 1 154 | 10 155 | 156 | 157 | 158 | 292 159 | {{10, 216}, {184, 27}} 160 | 161 | 162 | NO 163 | YES 164 | 7 165 | NO 166 | IBCocoaTouchFramework 167 | encrypted (base64) 168 | 169 | HiraKakuProN-W3 170 | 17 171 | 16 172 | 173 | 174 | 175 | 1 176 | 10 177 | 178 | 179 | 180 | 292 181 | {{0, 363}, {320, 97}} 182 | 183 | 184 | 185 | 1 186 | MSAwLjkwODM4MzQzNDcgMC45NTM4MDIxNjU3AA 187 | 188 | YES 189 | YES 190 | IBCocoaTouchFramework 191 | 192 | 193 | 194 | 2 195 | IBCocoaTouchFramework 196 | 197 | 198 | 199 | 200 | 292 201 | {{10, 333}, {184, 27}} 202 | 203 | 204 | NO 205 | YES 206 | 7 207 | NO 208 | IBCocoaTouchFramework 209 | ↓decrypted 210 | 211 | 212 | 213 | 1 214 | 10 215 | 216 | 217 | 218 | 292 219 | {{47, 114}, {182, 31}} 220 | 221 | 222 | NO 223 | YES 224 | IBCocoaTouchFramework 225 | 0 226 | sampleprivatekey 227 | 3 228 | 229 | 3 230 | MAA 231 | 232 | 2 233 | 234 | 235 | 236 | Helvetica 237 | 12 238 | 16 239 | 240 | YES 241 | 17 242 | 243 | IBCocoaTouchFramework 244 | 245 | 246 | 247 | 248 | 292 249 | {{237, 194}, {79, 37}} 250 | 251 | 252 | NO 253 | IBCocoaTouchFramework 254 | 0 255 | 0 256 | 257 | Helvetica-Bold 258 | 15 259 | 16 260 | 261 | 1 262 | encrypt 263 | 264 | 3 265 | MQA 266 | 267 | 268 | 1 269 | MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA 270 | 271 | 272 | 3 273 | MC41AA 274 | 275 | 276 | 277 | 278 | 292 279 | {{237, 324}, {79, 37}} 280 | 281 | 282 | NO 283 | IBCocoaTouchFramework 284 | 0 285 | 0 286 | 287 | 1 288 | decrypt 289 | 290 | 291 | 1 292 | MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA 293 | 294 | 295 | 296 | 297 | 298 | 292 299 | {{119, 158}, {94, 27}} 300 | 301 | 302 | NO 303 | IBCocoaTouchFramework 304 | 0 305 | 0 306 | YES 307 | 308 | 309 | {320, 460} 310 | 311 | 312 | YES 313 | YES 314 | IBCocoaTouchFramework 315 | 316 | 317 | {{0, 20}, {320, 460}} 318 | 319 | 320 | 321 | 3 322 | MC43NQA 323 | 324 | 325 | NO 326 | 327 | IBCocoaTouchFramework 328 | 329 | 330 | 331 | 332 | YES 333 | 334 | 335 | view 336 | 337 | 338 | 339 | 7 340 | 341 | 342 | 343 | message 344 | 345 | 346 | 347 | 68 348 | 349 | 350 | 351 | key 352 | 353 | 354 | 355 | 69 356 | 357 | 358 | 359 | encrypted 360 | 361 | 362 | 363 | 71 364 | 365 | 366 | 367 | decrypted 368 | 369 | 370 | 371 | 72 372 | 373 | 374 | 375 | encrypt: 376 | 377 | 378 | 7 379 | 380 | 73 381 | 382 | 383 | 384 | decrypt: 385 | 386 | 387 | 7 388 | 389 | 74 390 | 391 | 392 | 393 | scrollView 394 | 395 | 396 | 397 | 75 398 | 399 | 400 | 401 | separateline 402 | 403 | 404 | 405 | 88 406 | 407 | 408 | 409 | 410 | YES 411 | 412 | 0 413 | 414 | 415 | 416 | 417 | 418 | -1 419 | 420 | 421 | File's Owner 422 | 423 | 424 | -2 425 | 426 | 427 | 428 | 429 | 6 430 | 431 | 432 | YES 433 | 434 | 435 | 436 | 437 | 438 | 44 439 | 440 | 441 | YES 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 56 459 | 460 | 461 | 462 | 463 | 57 464 | 465 | 466 | 467 | 468 | 58 469 | 470 | 471 | 472 | 473 | 59 474 | 475 | 476 | 477 | 478 | 60 479 | 480 | 481 | 482 | 483 | 61 484 | 485 | 486 | 487 | 488 | 62 489 | 490 | 491 | 492 | 493 | 64 494 | 495 | 496 | 497 | 498 | 66 499 | 500 | 501 | 502 | 503 | 67 504 | 505 | 506 | 507 | 508 | 86 509 | 510 | 511 | 512 | 513 | 87 514 | 515 | 516 | 517 | 518 | 519 | 520 | YES 521 | 522 | YES 523 | -1.CustomClassName 524 | -2.CustomClassName 525 | 44.IBPluginDependency 526 | 56.IBPluginDependency 527 | 57.IBPluginDependency 528 | 58.IBPluginDependency 529 | 59.IBPluginDependency 530 | 6.IBEditorWindowLastContentRect 531 | 6.IBPluginDependency 532 | 60.IBPluginDependency 533 | 61.IBPluginDependency 534 | 62.IBPluginDependency 535 | 64.IBPluginDependency 536 | 66.IBPluginDependency 537 | 67.IBPluginDependency 538 | 86.IBPluginDependency 539 | 87.IBPluginDependency 540 | 541 | 542 | YES 543 | FBEncryptViewController 544 | UIResponder 545 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 546 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 547 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 548 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 549 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 550 | {{239, 654}, {320, 480}} 551 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 552 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 553 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 554 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 555 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 556 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 557 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 558 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 559 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 560 | 561 | 562 | 563 | YES 564 | 565 | 566 | 567 | 568 | 569 | YES 570 | 571 | 572 | 573 | 574 | 88 575 | 576 | 577 | 0 578 | IBCocoaTouchFramework 579 | 580 | com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 581 | 582 | 583 | YES 584 | 3 585 | 300 586 | 587 | 588 | -------------------------------------------------------------------------------- /FBEncrypt/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /FBEncrypt/en.lproj/MainWindow.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1024 5 | 10D571 6 | 786 7 | 1038.29 8 | 460.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 112 12 | 13 | 14 | YES 15 | 16 | 17 | 18 | YES 19 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 20 | 21 | 22 | YES 23 | 24 | YES 25 | 26 | 27 | YES 28 | 29 | 30 | 31 | YES 32 | 33 | IBFilesOwner 34 | IBCocoaTouchFramework 35 | 36 | 37 | IBFirstResponder 38 | IBCocoaTouchFramework 39 | 40 | 41 | IBCocoaTouchFramework 42 | 43 | 44 | FBEncryptViewController 45 | 46 | 47 | 1 48 | 49 | IBCocoaTouchFramework 50 | NO 51 | 52 | 53 | 54 | 292 55 | {320, 480} 56 | 57 | 1 58 | MSAxIDEAA 59 | 60 | NO 61 | NO 62 | 63 | IBCocoaTouchFramework 64 | YES 65 | 66 | 67 | 68 | 69 | YES 70 | 71 | 72 | delegate 73 | 74 | 75 | 76 | 4 77 | 78 | 79 | 80 | viewController 81 | 82 | 83 | 84 | 11 85 | 86 | 87 | 88 | window 89 | 90 | 91 | 92 | 14 93 | 94 | 95 | 96 | 97 | YES 98 | 99 | 0 100 | 101 | 102 | 103 | 104 | 105 | -1 106 | 107 | 108 | File's Owner 109 | 110 | 111 | 3 112 | 113 | 114 | FBEncrypt App Delegate 115 | 116 | 117 | -2 118 | 119 | 120 | 121 | 122 | 10 123 | 124 | 125 | 126 | 127 | 12 128 | 129 | 130 | 131 | 132 | 133 | 134 | YES 135 | 136 | YES 137 | -1.CustomClassName 138 | -2.CustomClassName 139 | 10.CustomClassName 140 | 10.IBEditorWindowLastContentRect 141 | 10.IBPluginDependency 142 | 12.IBEditorWindowLastContentRect 143 | 12.IBPluginDependency 144 | 3.CustomClassName 145 | 3.IBPluginDependency 146 | 147 | 148 | YES 149 | UIApplication 150 | UIResponder 151 | FBEncryptViewController 152 | {{234, 376}, {320, 480}} 153 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 154 | {{525, 346}, {320, 480}} 155 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 156 | FBEncryptAppDelegate 157 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 158 | 159 | 160 | 161 | YES 162 | 163 | 164 | YES 165 | 166 | 167 | 168 | 169 | YES 170 | 171 | 172 | YES 173 | 174 | 175 | 176 | 15 177 | 178 | 179 | 180 | YES 181 | 182 | UIWindow 183 | UIView 184 | 185 | IBUserSource 186 | 187 | 188 | 189 | 190 | FBEncryptAppDelegate 191 | NSObject 192 | 193 | YES 194 | 195 | YES 196 | viewController 197 | window 198 | 199 | 200 | YES 201 | FBEncryptViewController 202 | UIWindow 203 | 204 | 205 | 206 | YES 207 | 208 | YES 209 | viewController 210 | window 211 | 212 | 213 | YES 214 | 215 | viewController 216 | FBEncryptViewController 217 | 218 | 219 | window 220 | UIWindow 221 | 222 | 223 | 224 | 225 | IBProjectSource 226 | FBEncryptAppDelegate.h 227 | 228 | 229 | 230 | FBEncryptAppDelegate 231 | NSObject 232 | 233 | IBUserSource 234 | 235 | 236 | 237 | 238 | FBEncryptViewController 239 | UIViewController 240 | 241 | IBProjectSource 242 | FBEncryptViewController.h 243 | 244 | 245 | 246 | 247 | YES 248 | 249 | NSObject 250 | 251 | IBFrameworkSource 252 | Foundation.framework/Headers/NSError.h 253 | 254 | 255 | 256 | NSObject 257 | 258 | IBFrameworkSource 259 | Foundation.framework/Headers/NSFileManager.h 260 | 261 | 262 | 263 | NSObject 264 | 265 | IBFrameworkSource 266 | Foundation.framework/Headers/NSKeyValueCoding.h 267 | 268 | 269 | 270 | NSObject 271 | 272 | IBFrameworkSource 273 | Foundation.framework/Headers/NSKeyValueObserving.h 274 | 275 | 276 | 277 | NSObject 278 | 279 | IBFrameworkSource 280 | Foundation.framework/Headers/NSKeyedArchiver.h 281 | 282 | 283 | 284 | NSObject 285 | 286 | IBFrameworkSource 287 | Foundation.framework/Headers/NSObject.h 288 | 289 | 290 | 291 | NSObject 292 | 293 | IBFrameworkSource 294 | Foundation.framework/Headers/NSRunLoop.h 295 | 296 | 297 | 298 | NSObject 299 | 300 | IBFrameworkSource 301 | Foundation.framework/Headers/NSThread.h 302 | 303 | 304 | 305 | NSObject 306 | 307 | IBFrameworkSource 308 | Foundation.framework/Headers/NSURL.h 309 | 310 | 311 | 312 | NSObject 313 | 314 | IBFrameworkSource 315 | Foundation.framework/Headers/NSURLConnection.h 316 | 317 | 318 | 319 | NSObject 320 | 321 | IBFrameworkSource 322 | UIKit.framework/Headers/UIAccessibility.h 323 | 324 | 325 | 326 | NSObject 327 | 328 | IBFrameworkSource 329 | UIKit.framework/Headers/UINibLoading.h 330 | 331 | 332 | 333 | NSObject 334 | 335 | IBFrameworkSource 336 | UIKit.framework/Headers/UIResponder.h 337 | 338 | 339 | 340 | UIApplication 341 | UIResponder 342 | 343 | IBFrameworkSource 344 | UIKit.framework/Headers/UIApplication.h 345 | 346 | 347 | 348 | UIResponder 349 | NSObject 350 | 351 | 352 | 353 | UISearchBar 354 | UIView 355 | 356 | IBFrameworkSource 357 | UIKit.framework/Headers/UISearchBar.h 358 | 359 | 360 | 361 | UISearchDisplayController 362 | NSObject 363 | 364 | IBFrameworkSource 365 | UIKit.framework/Headers/UISearchDisplayController.h 366 | 367 | 368 | 369 | UIView 370 | 371 | IBFrameworkSource 372 | UIKit.framework/Headers/UITextField.h 373 | 374 | 375 | 376 | UIView 377 | UIResponder 378 | 379 | IBFrameworkSource 380 | UIKit.framework/Headers/UIView.h 381 | 382 | 383 | 384 | UIViewController 385 | 386 | IBFrameworkSource 387 | UIKit.framework/Headers/UINavigationController.h 388 | 389 | 390 | 391 | UIViewController 392 | 393 | IBFrameworkSource 394 | UIKit.framework/Headers/UIPopoverController.h 395 | 396 | 397 | 398 | UIViewController 399 | 400 | IBFrameworkSource 401 | UIKit.framework/Headers/UISplitViewController.h 402 | 403 | 404 | 405 | UIViewController 406 | 407 | IBFrameworkSource 408 | UIKit.framework/Headers/UITabBarController.h 409 | 410 | 411 | 412 | UIViewController 413 | UIResponder 414 | 415 | IBFrameworkSource 416 | UIKit.framework/Headers/UIViewController.h 417 | 418 | 419 | 420 | UIWindow 421 | UIView 422 | 423 | IBFrameworkSource 424 | UIKit.framework/Headers/UIWindow.h 425 | 426 | 427 | 428 | 429 | 0 430 | IBCocoaTouchFramework 431 | 432 | com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS 433 | 434 | 435 | 436 | com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 437 | 438 | 439 | YES 440 | FBEncrypt.xcodeproj 441 | 3 442 | 112 443 | 444 | 445 | -------------------------------------------------------------------------------- /FBEncrypt/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // FBEncrypt 4 | // 5 | // Created by Hiroshi Hashiguchi on 11/05/30. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /FBEncryptTests/FBEncryptTests.h: -------------------------------------------------------------------------------- 1 | // 2 | // FBEncryptTests.h 3 | // FBEncryptTests 4 | // 5 | // Created by Hiroshi Hashiguchi on 11/05/30. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface FBEncryptTests : SenTestCase { 13 | @private 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /FBEncryptTests/FBEncryptTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // FBEncryptTests.m 3 | // FBEncryptTests 4 | // 5 | // Created by Hiroshi Hashiguchi on 11/05/30. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "FBEncryptTests.h" 10 | #import "FBEncryptorAES.h" 11 | #import "NSData+Base64.h" 12 | 13 | @implementation FBEncryptTests 14 | 15 | - (void)setUp 16 | { 17 | [super setUp]; 18 | 19 | // Set-up code here. 20 | } 21 | 22 | - (void)tearDown 23 | { 24 | // Tear-down code here. 25 | 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testEncrypt 30 | { 31 | STAssertEqualObjects([FBEncryptorAES encryptBase64String:@"Write text here and touch encrypt button and confirm the encrypted message." 32 | keyString:@"sampleprivatekey" 33 | separateLines:NO], 34 | @"kWxGYHe3mYeeWTdpnM7V4/TZ1Dmg+PLUkkOdCc8AQxAz+6oDf7kCBMWMwOUFMe7m7LxzSi9T43Pb1XaG7409vb0QaDO8eZMHmJgXx/oGbEA=", 35 | nil); 36 | 37 | STAssertEqualObjects([FBEncryptorAES encryptBase64String:@"Write text here and touch encrypt button and confirm the encrypted message." 38 | keyString:@"sampleprivatekey" 39 | separateLines:YES], 40 | //123456789+123456789+123456789+123456789+123456789+123456789+1234|<=64 41 | @"kWxGYHe3mYeeWTdpnM7V4/TZ1Dmg+PLUkkOdCc8AQxAz+6oDf7kCBMWMwOUFMe7m\r\n" \ 42 | @"7LxzSi9T43Pb1XaG7409vb0QaDO8eZMHmJgXx/oGbEA=", 43 | nil); 44 | } 45 | 46 | - (void)testDecrypt 47 | { 48 | STAssertEqualObjects([FBEncryptorAES decryptBase64String:@"kWxGYHe3mYeeWTdpnM7V4/TZ1Dmg+PLUkkOdCc8AQxAz+6oDf7kCBMWMwOUFMe7m7LxzSi9T43Pb1XaG7409vb0QaDO8eZMHmJgXx/oGbEA=" 49 | keyString:@"sampleprivatekey"], 50 | @"Write text here and touch encrypt button and confirm the encrypted message.", 51 | nil); 52 | } 53 | 54 | - (void)testGenerateIv 55 | { 56 | NSData* iv = [FBEncryptorAES generateIv]; 57 | STAssertEquals([iv length], (NSUInteger)FBENCRYPT_BLOCK_SIZE, nil); 58 | } 59 | 60 | - (void)testHexStringAndDataConvertor 61 | { 62 | NSString* hexString = @"b20cd8d972e65762824cc3190040388c"; 63 | const unsigned char raw[] = { 64 | 0xb2, 0x0c, 0xd8, 0xd9, 65 | 0x72, 0xe6, 0x57, 0x62, 66 | 0x82, 0x4c, 0xc3, 0x19, 67 | 0x00, 0x40, 0x38, 0x8c}; 68 | NSData* data = [NSData dataWithBytes:raw length:FBENCRYPT_BLOCK_SIZE]; 69 | NSString* convertedString = [FBEncryptorAES hexStringForData:data]; 70 | NSData* convertedData = [FBEncryptorAES dataForHexString:hexString]; 71 | 72 | STAssertEqualObjects(convertedString, hexString, nil); 73 | STAssertEqualObjects(convertedData, data, nil); 74 | STAssertEqualObjects([FBEncryptorAES hexStringForData:convertedData], hexString, nil); 75 | } 76 | 77 | - (void)testRawAPI 78 | { 79 | NSData* data = [@"Write text here and touch encrypt button and confirm the encrypted message." 80 | dataUsingEncoding:NSUTF8StringEncoding]; 81 | NSData* key = [@"sampleprivatekey" dataUsingEncoding:NSUTF8StringEncoding]; 82 | NSData* iv = [@"initialvector123" dataUsingEncoding:NSUTF8StringEncoding]; 83 | 84 | NSData* encryptedData = [NSData dataFromBase64String:@"rlBB3bQZmLKlNxcS8kgYaJsaWw7nwfAI6ue8Q/WPaWc0zdTx7tm2y2AhRJlGwQcP+088Ar341WxLvGfZCQgM3BxwZSpH+xAevTQCwL8GQfw="]; 85 | 86 | STAssertEqualObjects([FBEncryptorAES encryptData:data key:key iv:iv], encryptedData, nil); 87 | STAssertEqualObjects([FBEncryptorAES decryptData:encryptedData key:key iv:iv], data, nil); 88 | } 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /FBEncryptTests/FBEncryptorTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | jp.5tec.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /FBEncryptTests/FBEncryptorTests-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'FBEncryptTests' target in the 'FBEncryptTests' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /FBEncryptTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /FBEncryptor.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4C1000A5139324DB00C9257E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C1000A4139324DB00C9257E /* UIKit.framework */; }; 11 | 4C1000A7139324DB00C9257E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C1000A6139324DB00C9257E /* Foundation.framework */; }; 12 | 4C1000A9139324DB00C9257E /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C1000A8139324DB00C9257E /* CoreGraphics.framework */; }; 13 | 4C1000AF139324DB00C9257E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4C1000AD139324DB00C9257E /* InfoPlist.strings */; }; 14 | 4C1000B2139324DB00C9257E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C1000B1139324DB00C9257E /* main.m */; }; 15 | 4C1000B5139324DB00C9257E /* FBEncryptAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C1000B4139324DB00C9257E /* FBEncryptAppDelegate.m */; }; 16 | 4C1000B8139324DB00C9257E /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C1000B6139324DB00C9257E /* MainWindow.xib */; }; 17 | 4C1000BB139324DB00C9257E /* FBEncryptViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C1000BA139324DB00C9257E /* FBEncryptViewController.m */; }; 18 | 4C1000BE139324DB00C9257E /* FBEncryptViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C1000BC139324DB00C9257E /* FBEncryptViewController.xib */; }; 19 | 4C1000C5139324DB00C9257E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C1000A4139324DB00C9257E /* UIKit.framework */; }; 20 | 4C1000C6139324DB00C9257E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C1000A6139324DB00C9257E /* Foundation.framework */; }; 21 | 4C1000C7139324DB00C9257E /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C1000A8139324DB00C9257E /* CoreGraphics.framework */; }; 22 | 4C1000CF139324DB00C9257E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4C1000CD139324DB00C9257E /* InfoPlist.strings */; }; 23 | 4C1000D2139324DB00C9257E /* FBEncryptTests.h in Resources */ = {isa = PBXBuildFile; fileRef = 4C1000D1139324DB00C9257E /* FBEncryptTests.h */; }; 24 | 4C1000D4139324DB00C9257E /* FBEncryptTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C1000D3139324DB00C9257E /* FBEncryptTests.m */; }; 25 | 4C1000E01393250900C9257E /* FBEncryptorAES.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C1000DF1393250900C9257E /* FBEncryptorAES.m */; }; 26 | 4C1000E11393250900C9257E /* FBEncryptorAES.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C1000DF1393250900C9257E /* FBEncryptorAES.m */; }; 27 | 4C10010E13932FC400C9257E /* NSData+Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C10010C13932FC400C9257E /* NSData+Base64.m */; }; 28 | 4C10010F13932FC400C9257E /* NSData+Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C10010C13932FC400C9257E /* NSData+Base64.m */; }; 29 | /* End PBXBuildFile section */ 30 | 31 | /* Begin PBXContainerItemProxy section */ 32 | 4C1000C8139324DB00C9257E /* PBXContainerItemProxy */ = { 33 | isa = PBXContainerItemProxy; 34 | containerPortal = 4C100097139324DA00C9257E /* Project object */; 35 | proxyType = 1; 36 | remoteGlobalIDString = 4C10009F139324DB00C9257E; 37 | remoteInfo = FBEncrypt; 38 | }; 39 | /* End PBXContainerItemProxy section */ 40 | 41 | /* Begin PBXFileReference section */ 42 | 4C1000A0139324DB00C9257E /* FBEncryptor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FBEncryptor.app; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 4C1000A4139324DB00C9257E /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 44 | 4C1000A6139324DB00C9257E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 45 | 4C1000A8139324DB00C9257E /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 46 | 4C1000AC139324DB00C9257E /* FBEncryptor-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "FBEncryptor-Info.plist"; sourceTree = ""; }; 47 | 4C1000AE139324DB00C9257E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 48 | 4C1000B0139324DB00C9257E /* FBEncryptor-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FBEncryptor-Prefix.pch"; sourceTree = ""; }; 49 | 4C1000B1139324DB00C9257E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 50 | 4C1000B3139324DB00C9257E /* FBEncryptAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBEncryptAppDelegate.h; sourceTree = ""; }; 51 | 4C1000B4139324DB00C9257E /* FBEncryptAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBEncryptAppDelegate.m; sourceTree = ""; }; 52 | 4C1000B7139324DB00C9257E /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainWindow.xib; sourceTree = ""; }; 53 | 4C1000B9139324DB00C9257E /* FBEncryptViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBEncryptViewController.h; sourceTree = ""; }; 54 | 4C1000BA139324DB00C9257E /* FBEncryptViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBEncryptViewController.m; sourceTree = ""; }; 55 | 4C1000BD139324DB00C9257E /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/FBEncryptViewController.xib; sourceTree = ""; }; 56 | 4C1000C4139324DB00C9257E /* FBEncryptorTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FBEncryptorTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; 57 | 4C1000CC139324DB00C9257E /* FBEncryptorTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "FBEncryptorTests-Info.plist"; sourceTree = ""; }; 58 | 4C1000CE139324DB00C9257E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 59 | 4C1000D0139324DB00C9257E /* FBEncryptorTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FBEncryptorTests-Prefix.pch"; sourceTree = ""; }; 60 | 4C1000D1139324DB00C9257E /* FBEncryptTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBEncryptTests.h; sourceTree = ""; }; 61 | 4C1000D3139324DB00C9257E /* FBEncryptTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBEncryptTests.m; sourceTree = ""; }; 62 | 4C1000DE1393250900C9257E /* FBEncryptorAES.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBEncryptorAES.h; sourceTree = ""; }; 63 | 4C1000DF1393250900C9257E /* FBEncryptorAES.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBEncryptorAES.m; sourceTree = ""; }; 64 | 4C10010C13932FC400C9257E /* NSData+Base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+Base64.m"; sourceTree = ""; }; 65 | 4C10010D13932FC400C9257E /* NSData+Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+Base64.h"; sourceTree = ""; }; 66 | 4C7E35C313974826000D7909 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.md; sourceTree = ""; }; 67 | /* End PBXFileReference section */ 68 | 69 | /* Begin PBXFrameworksBuildPhase section */ 70 | 4C10009D139324DB00C9257E /* Frameworks */ = { 71 | isa = PBXFrameworksBuildPhase; 72 | buildActionMask = 2147483647; 73 | files = ( 74 | 4C1000A5139324DB00C9257E /* UIKit.framework in Frameworks */, 75 | 4C1000A7139324DB00C9257E /* Foundation.framework in Frameworks */, 76 | 4C1000A9139324DB00C9257E /* CoreGraphics.framework in Frameworks */, 77 | ); 78 | runOnlyForDeploymentPostprocessing = 0; 79 | }; 80 | 4C1000C0139324DB00C9257E /* Frameworks */ = { 81 | isa = PBXFrameworksBuildPhase; 82 | buildActionMask = 2147483647; 83 | files = ( 84 | 4C1000C5139324DB00C9257E /* UIKit.framework in Frameworks */, 85 | 4C1000C6139324DB00C9257E /* Foundation.framework in Frameworks */, 86 | 4C1000C7139324DB00C9257E /* CoreGraphics.framework in Frameworks */, 87 | ); 88 | runOnlyForDeploymentPostprocessing = 0; 89 | }; 90 | /* End PBXFrameworksBuildPhase section */ 91 | 92 | /* Begin PBXGroup section */ 93 | 4C100095139324DA00C9257E = { 94 | isa = PBXGroup; 95 | children = ( 96 | 4C7E35C313974826000D7909 /* README.md */, 97 | 4C1000DD139324F300C9257E /* FBEncryptor */, 98 | 4C1000AA139324DB00C9257E /* Test Application */, 99 | 4C1000CA139324DB00C9257E /* FBEncryptTests */, 100 | 4C1000A3139324DB00C9257E /* Frameworks */, 101 | 4C1000A1139324DB00C9257E /* Products */, 102 | ); 103 | sourceTree = ""; 104 | }; 105 | 4C1000A1139324DB00C9257E /* Products */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 4C1000A0139324DB00C9257E /* FBEncryptor.app */, 109 | 4C1000C4139324DB00C9257E /* FBEncryptorTests.octest */, 110 | ); 111 | name = Products; 112 | sourceTree = ""; 113 | }; 114 | 4C1000A3139324DB00C9257E /* Frameworks */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | 4C1000A4139324DB00C9257E /* UIKit.framework */, 118 | 4C1000A6139324DB00C9257E /* Foundation.framework */, 119 | 4C1000A8139324DB00C9257E /* CoreGraphics.framework */, 120 | ); 121 | name = Frameworks; 122 | sourceTree = ""; 123 | }; 124 | 4C1000AA139324DB00C9257E /* Test Application */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | 4C1000B3139324DB00C9257E /* FBEncryptAppDelegate.h */, 128 | 4C1000B4139324DB00C9257E /* FBEncryptAppDelegate.m */, 129 | 4C1000B6139324DB00C9257E /* MainWindow.xib */, 130 | 4C1000B9139324DB00C9257E /* FBEncryptViewController.h */, 131 | 4C1000BA139324DB00C9257E /* FBEncryptViewController.m */, 132 | 4C1000BC139324DB00C9257E /* FBEncryptViewController.xib */, 133 | 4C1000AB139324DB00C9257E /* Supporting Files */, 134 | ); 135 | name = "Test Application"; 136 | path = FBEncrypt; 137 | sourceTree = ""; 138 | }; 139 | 4C1000AB139324DB00C9257E /* Supporting Files */ = { 140 | isa = PBXGroup; 141 | children = ( 142 | 4C1000AC139324DB00C9257E /* FBEncryptor-Info.plist */, 143 | 4C1000AD139324DB00C9257E /* InfoPlist.strings */, 144 | 4C1000B0139324DB00C9257E /* FBEncryptor-Prefix.pch */, 145 | 4C1000B1139324DB00C9257E /* main.m */, 146 | ); 147 | name = "Supporting Files"; 148 | sourceTree = ""; 149 | }; 150 | 4C1000CA139324DB00C9257E /* FBEncryptTests */ = { 151 | isa = PBXGroup; 152 | children = ( 153 | 4C1000D1139324DB00C9257E /* FBEncryptTests.h */, 154 | 4C1000D3139324DB00C9257E /* FBEncryptTests.m */, 155 | 4C1000CB139324DB00C9257E /* Supporting Files */, 156 | ); 157 | path = FBEncryptTests; 158 | sourceTree = ""; 159 | }; 160 | 4C1000CB139324DB00C9257E /* Supporting Files */ = { 161 | isa = PBXGroup; 162 | children = ( 163 | 4C1000CC139324DB00C9257E /* FBEncryptorTests-Info.plist */, 164 | 4C1000CD139324DB00C9257E /* InfoPlist.strings */, 165 | 4C1000D0139324DB00C9257E /* FBEncryptorTests-Prefix.pch */, 166 | ); 167 | name = "Supporting Files"; 168 | sourceTree = ""; 169 | }; 170 | 4C1000DD139324F300C9257E /* FBEncryptor */ = { 171 | isa = PBXGroup; 172 | children = ( 173 | 4C1000DE1393250900C9257E /* FBEncryptorAES.h */, 174 | 4C1000DF1393250900C9257E /* FBEncryptorAES.m */, 175 | 4C10010C13932FC400C9257E /* NSData+Base64.m */, 176 | 4C10010D13932FC400C9257E /* NSData+Base64.h */, 177 | ); 178 | name = FBEncryptor; 179 | sourceTree = ""; 180 | }; 181 | /* End PBXGroup section */ 182 | 183 | /* Begin PBXNativeTarget section */ 184 | 4C10009F139324DB00C9257E /* FBEncryptor */ = { 185 | isa = PBXNativeTarget; 186 | buildConfigurationList = 4C1000D7139324DB00C9257E /* Build configuration list for PBXNativeTarget "FBEncryptor" */; 187 | buildPhases = ( 188 | 4C10009C139324DB00C9257E /* Sources */, 189 | 4C10009D139324DB00C9257E /* Frameworks */, 190 | 4C10009E139324DB00C9257E /* Resources */, 191 | ); 192 | buildRules = ( 193 | ); 194 | dependencies = ( 195 | ); 196 | name = FBEncryptor; 197 | productName = FBEncrypt; 198 | productReference = 4C1000A0139324DB00C9257E /* FBEncryptor.app */; 199 | productType = "com.apple.product-type.application"; 200 | }; 201 | 4C1000C3139324DB00C9257E /* FBEncryptorTests */ = { 202 | isa = PBXNativeTarget; 203 | buildConfigurationList = 4C1000DA139324DB00C9257E /* Build configuration list for PBXNativeTarget "FBEncryptorTests" */; 204 | buildPhases = ( 205 | 4C1000BF139324DB00C9257E /* Sources */, 206 | 4C1000C0139324DB00C9257E /* Frameworks */, 207 | 4C1000C1139324DB00C9257E /* Resources */, 208 | 4C1000C2139324DB00C9257E /* ShellScript */, 209 | ); 210 | buildRules = ( 211 | ); 212 | dependencies = ( 213 | 4C1000C9139324DB00C9257E /* PBXTargetDependency */, 214 | ); 215 | name = FBEncryptorTests; 216 | productName = FBEncryptTests; 217 | productReference = 4C1000C4139324DB00C9257E /* FBEncryptorTests.octest */; 218 | productType = "com.apple.product-type.bundle"; 219 | }; 220 | /* End PBXNativeTarget section */ 221 | 222 | /* Begin PBXProject section */ 223 | 4C100097139324DA00C9257E /* Project object */ = { 224 | isa = PBXProject; 225 | buildConfigurationList = 4C10009A139324DA00C9257E /* Build configuration list for PBXProject "FBEncryptor" */; 226 | compatibilityVersion = "Xcode 3.2"; 227 | developmentRegion = English; 228 | hasScannedForEncodings = 0; 229 | knownRegions = ( 230 | en, 231 | ); 232 | mainGroup = 4C100095139324DA00C9257E; 233 | productRefGroup = 4C1000A1139324DB00C9257E /* Products */; 234 | projectDirPath = ""; 235 | projectRoot = ""; 236 | targets = ( 237 | 4C10009F139324DB00C9257E /* FBEncryptor */, 238 | 4C1000C3139324DB00C9257E /* FBEncryptorTests */, 239 | ); 240 | }; 241 | /* End PBXProject section */ 242 | 243 | /* Begin PBXResourcesBuildPhase section */ 244 | 4C10009E139324DB00C9257E /* Resources */ = { 245 | isa = PBXResourcesBuildPhase; 246 | buildActionMask = 2147483647; 247 | files = ( 248 | 4C1000AF139324DB00C9257E /* InfoPlist.strings in Resources */, 249 | 4C1000B8139324DB00C9257E /* MainWindow.xib in Resources */, 250 | 4C1000BE139324DB00C9257E /* FBEncryptViewController.xib in Resources */, 251 | ); 252 | runOnlyForDeploymentPostprocessing = 0; 253 | }; 254 | 4C1000C1139324DB00C9257E /* Resources */ = { 255 | isa = PBXResourcesBuildPhase; 256 | buildActionMask = 2147483647; 257 | files = ( 258 | 4C1000CF139324DB00C9257E /* InfoPlist.strings in Resources */, 259 | 4C1000D2139324DB00C9257E /* FBEncryptTests.h in Resources */, 260 | ); 261 | runOnlyForDeploymentPostprocessing = 0; 262 | }; 263 | /* End PBXResourcesBuildPhase section */ 264 | 265 | /* Begin PBXShellScriptBuildPhase section */ 266 | 4C1000C2139324DB00C9257E /* ShellScript */ = { 267 | isa = PBXShellScriptBuildPhase; 268 | buildActionMask = 2147483647; 269 | files = ( 270 | ); 271 | inputPaths = ( 272 | ); 273 | outputPaths = ( 274 | ); 275 | runOnlyForDeploymentPostprocessing = 0; 276 | shellPath = /bin/sh; 277 | shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n"; 278 | }; 279 | /* End PBXShellScriptBuildPhase section */ 280 | 281 | /* Begin PBXSourcesBuildPhase section */ 282 | 4C10009C139324DB00C9257E /* Sources */ = { 283 | isa = PBXSourcesBuildPhase; 284 | buildActionMask = 2147483647; 285 | files = ( 286 | 4C1000B2139324DB00C9257E /* main.m in Sources */, 287 | 4C1000B5139324DB00C9257E /* FBEncryptAppDelegate.m in Sources */, 288 | 4C1000BB139324DB00C9257E /* FBEncryptViewController.m in Sources */, 289 | 4C1000E01393250900C9257E /* FBEncryptorAES.m in Sources */, 290 | 4C10010E13932FC400C9257E /* NSData+Base64.m in Sources */, 291 | ); 292 | runOnlyForDeploymentPostprocessing = 0; 293 | }; 294 | 4C1000BF139324DB00C9257E /* Sources */ = { 295 | isa = PBXSourcesBuildPhase; 296 | buildActionMask = 2147483647; 297 | files = ( 298 | 4C1000D4139324DB00C9257E /* FBEncryptTests.m in Sources */, 299 | 4C1000E11393250900C9257E /* FBEncryptorAES.m in Sources */, 300 | 4C10010F13932FC400C9257E /* NSData+Base64.m in Sources */, 301 | ); 302 | runOnlyForDeploymentPostprocessing = 0; 303 | }; 304 | /* End PBXSourcesBuildPhase section */ 305 | 306 | /* Begin PBXTargetDependency section */ 307 | 4C1000C9139324DB00C9257E /* PBXTargetDependency */ = { 308 | isa = PBXTargetDependency; 309 | target = 4C10009F139324DB00C9257E /* FBEncryptor */; 310 | targetProxy = 4C1000C8139324DB00C9257E /* PBXContainerItemProxy */; 311 | }; 312 | /* End PBXTargetDependency section */ 313 | 314 | /* Begin PBXVariantGroup section */ 315 | 4C1000AD139324DB00C9257E /* InfoPlist.strings */ = { 316 | isa = PBXVariantGroup; 317 | children = ( 318 | 4C1000AE139324DB00C9257E /* en */, 319 | ); 320 | name = InfoPlist.strings; 321 | sourceTree = ""; 322 | }; 323 | 4C1000B6139324DB00C9257E /* MainWindow.xib */ = { 324 | isa = PBXVariantGroup; 325 | children = ( 326 | 4C1000B7139324DB00C9257E /* en */, 327 | ); 328 | name = MainWindow.xib; 329 | sourceTree = ""; 330 | }; 331 | 4C1000BC139324DB00C9257E /* FBEncryptViewController.xib */ = { 332 | isa = PBXVariantGroup; 333 | children = ( 334 | 4C1000BD139324DB00C9257E /* en */, 335 | ); 336 | name = FBEncryptViewController.xib; 337 | sourceTree = ""; 338 | }; 339 | 4C1000CD139324DB00C9257E /* InfoPlist.strings */ = { 340 | isa = PBXVariantGroup; 341 | children = ( 342 | 4C1000CE139324DB00C9257E /* en */, 343 | ); 344 | name = InfoPlist.strings; 345 | sourceTree = ""; 346 | }; 347 | /* End PBXVariantGroup section */ 348 | 349 | /* Begin XCBuildConfiguration section */ 350 | 4C1000D5139324DB00C9257E /* Debug */ = { 351 | isa = XCBuildConfiguration; 352 | buildSettings = { 353 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 354 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 355 | GCC_C_LANGUAGE_STANDARD = gnu99; 356 | GCC_OPTIMIZATION_LEVEL = 0; 357 | GCC_PREPROCESSOR_DEFINITIONS = DEBUG; 358 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 359 | GCC_VERSION = com.apple.compilers.llvmgcc42; 360 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 361 | GCC_WARN_UNUSED_VARIABLE = YES; 362 | IPHONEOS_DEPLOYMENT_TARGET = 4.3; 363 | SDKROOT = iphoneos; 364 | }; 365 | name = Debug; 366 | }; 367 | 4C1000D6139324DB00C9257E /* Release */ = { 368 | isa = XCBuildConfiguration; 369 | buildSettings = { 370 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 371 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 372 | GCC_C_LANGUAGE_STANDARD = gnu99; 373 | GCC_VERSION = com.apple.compilers.llvmgcc42; 374 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 375 | GCC_WARN_UNUSED_VARIABLE = YES; 376 | IPHONEOS_DEPLOYMENT_TARGET = 4.3; 377 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 378 | SDKROOT = iphoneos; 379 | }; 380 | name = Release; 381 | }; 382 | 4C1000D8139324DB00C9257E /* Debug */ = { 383 | isa = XCBuildConfiguration; 384 | buildSettings = { 385 | ALWAYS_SEARCH_USER_PATHS = NO; 386 | COPY_PHASE_STRIP = NO; 387 | GCC_DYNAMIC_NO_PIC = NO; 388 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 389 | GCC_PREFIX_HEADER = "FBEncrypt/FBEncryptor-Prefix.pch"; 390 | INFOPLIST_FILE = "FBEncrypt/FBEncryptor-Info.plist"; 391 | PRODUCT_NAME = FBEncryptor; 392 | WRAPPER_EXTENSION = app; 393 | }; 394 | name = Debug; 395 | }; 396 | 4C1000D9139324DB00C9257E /* Release */ = { 397 | isa = XCBuildConfiguration; 398 | buildSettings = { 399 | ALWAYS_SEARCH_USER_PATHS = NO; 400 | COPY_PHASE_STRIP = YES; 401 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 402 | GCC_PREFIX_HEADER = "FBEncrypt/FBEncryptor-Prefix.pch"; 403 | INFOPLIST_FILE = "FBEncrypt/FBEncryptor-Info.plist"; 404 | PRODUCT_NAME = FBEncryptor; 405 | VALIDATE_PRODUCT = YES; 406 | WRAPPER_EXTENSION = app; 407 | }; 408 | name = Release; 409 | }; 410 | 4C1000DB139324DB00C9257E /* Debug */ = { 411 | isa = XCBuildConfiguration; 412 | buildSettings = { 413 | ALWAYS_SEARCH_USER_PATHS = NO; 414 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/FBEncryptor.app/FBEncryptor"; 415 | FRAMEWORK_SEARCH_PATHS = ( 416 | "$(SDKROOT)/Developer/Library/Frameworks", 417 | "$(DEVELOPER_LIBRARY_DIR)/Frameworks", 418 | ); 419 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 420 | GCC_PREFIX_HEADER = "FBEncryptTests/FBEncryptorTests-Prefix.pch"; 421 | INFOPLIST_FILE = "FBEncryptTests/FBEncryptorTests-Info.plist"; 422 | OTHER_LDFLAGS = ( 423 | "-framework", 424 | SenTestingKit, 425 | ); 426 | PRODUCT_NAME = FBEncryptorTests; 427 | TEST_HOST = "$(BUNDLE_LOADER)"; 428 | WRAPPER_EXTENSION = octest; 429 | }; 430 | name = Debug; 431 | }; 432 | 4C1000DC139324DB00C9257E /* Release */ = { 433 | isa = XCBuildConfiguration; 434 | buildSettings = { 435 | ALWAYS_SEARCH_USER_PATHS = NO; 436 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/FBEncryptor.app/FBEncryptor"; 437 | FRAMEWORK_SEARCH_PATHS = ( 438 | "$(SDKROOT)/Developer/Library/Frameworks", 439 | "$(DEVELOPER_LIBRARY_DIR)/Frameworks", 440 | ); 441 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 442 | GCC_PREFIX_HEADER = "FBEncryptTests/FBEncryptorTests-Prefix.pch"; 443 | INFOPLIST_FILE = "FBEncryptTests/FBEncryptorTests-Info.plist"; 444 | OTHER_LDFLAGS = ( 445 | "-framework", 446 | SenTestingKit, 447 | ); 448 | PRODUCT_NAME = FBEncryptorTests; 449 | TEST_HOST = "$(BUNDLE_LOADER)"; 450 | WRAPPER_EXTENSION = octest; 451 | }; 452 | name = Release; 453 | }; 454 | /* End XCBuildConfiguration section */ 455 | 456 | /* Begin XCConfigurationList section */ 457 | 4C10009A139324DA00C9257E /* Build configuration list for PBXProject "FBEncryptor" */ = { 458 | isa = XCConfigurationList; 459 | buildConfigurations = ( 460 | 4C1000D5139324DB00C9257E /* Debug */, 461 | 4C1000D6139324DB00C9257E /* Release */, 462 | ); 463 | defaultConfigurationIsVisible = 0; 464 | defaultConfigurationName = Release; 465 | }; 466 | 4C1000D7139324DB00C9257E /* Build configuration list for PBXNativeTarget "FBEncryptor" */ = { 467 | isa = XCConfigurationList; 468 | buildConfigurations = ( 469 | 4C1000D8139324DB00C9257E /* Debug */, 470 | 4C1000D9139324DB00C9257E /* Release */, 471 | ); 472 | defaultConfigurationIsVisible = 0; 473 | defaultConfigurationName = Release; 474 | }; 475 | 4C1000DA139324DB00C9257E /* Build configuration list for PBXNativeTarget "FBEncryptorTests" */ = { 476 | isa = XCConfigurationList; 477 | buildConfigurations = ( 478 | 4C1000DB139324DB00C9257E /* Debug */, 479 | 4C1000DC139324DB00C9257E /* Release */, 480 | ); 481 | defaultConfigurationIsVisible = 0; 482 | defaultConfigurationName = Release; 483 | }; 484 | /* End XCConfigurationList section */ 485 | }; 486 | rootObject = 4C100097139324DA00C9257E /* Project object */; 487 | } 488 | -------------------------------------------------------------------------------- /FBEncryptorAES.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2011 Five-technology Co.,Ltd. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | #import 24 | #import 25 | 26 | #define FBENCRYPT_ALGORITHM kCCAlgorithmAES128 27 | #define FBENCRYPT_BLOCK_SIZE kCCBlockSizeAES128 28 | #define FBENCRYPT_KEY_SIZE kCCKeySizeAES256 29 | 30 | @interface FBEncryptorAES : NSObject { 31 | 32 | } 33 | 34 | //----------------- 35 | // API (raw data) 36 | //----------------- 37 | + (NSData*)generateIv; 38 | + (NSData*)encryptData:(NSData*)data key:(NSData*)key iv:(NSData*)iv; 39 | + (NSData*)decryptData:(NSData*)data key:(NSData*)key iv:(NSData*)iv; 40 | 41 | 42 | //----------------- 43 | // API (base64) 44 | //----------------- 45 | // the return value of encrypteMessage: and 'encryptedMessage' are encoded with base64. 46 | // 47 | + (NSString*)encryptBase64String:(NSString*)string keyString:(NSString*)keyString separateLines:(BOOL)separateLines; 48 | + (NSString*)decryptBase64String:(NSString*)encryptedBase64String keyString:(NSString*)keyString; 49 | 50 | //----------------- 51 | // API (utilities) 52 | //----------------- 53 | + (NSString*)hexStringForData:(NSData*)data; 54 | + (NSData*)dataForHexString:(NSString*)hexString; 55 | 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /FBEncryptorAES.m: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2011 Five-technology Co.,Ltd. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | #import "FBEncryptorAES.h" 24 | #import "NSData+Base64.h" 25 | 26 | @implementation FBEncryptorAES 27 | 28 | #pragma mark - 29 | #pragma mark Initialization and deallcation 30 | 31 | 32 | #pragma mark - 33 | #pragma mark Praivate 34 | 35 | 36 | #pragma mark - 37 | #pragma mark API 38 | 39 | + (NSData*)encryptData:(NSData*)data key:(NSData*)key iv:(NSData*)iv; 40 | { 41 | NSData* result = nil; 42 | 43 | // setup key 44 | unsigned char cKey[FBENCRYPT_KEY_SIZE]; 45 | bzero(cKey, sizeof(cKey)); 46 | [key getBytes:cKey length:FBENCRYPT_KEY_SIZE]; 47 | 48 | // setup iv 49 | char cIv[FBENCRYPT_BLOCK_SIZE]; 50 | bzero(cIv, FBENCRYPT_BLOCK_SIZE); 51 | if (iv) { 52 | [iv getBytes:cIv length:FBENCRYPT_BLOCK_SIZE]; 53 | } 54 | 55 | // setup output buffer 56 | size_t bufferSize = [data length] + FBENCRYPT_BLOCK_SIZE; 57 | void *buffer = malloc(bufferSize); 58 | 59 | // do encrypt 60 | size_t encryptedSize = 0; 61 | CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, 62 | FBENCRYPT_ALGORITHM, 63 | kCCOptionPKCS7Padding, 64 | cKey, 65 | FBENCRYPT_KEY_SIZE, 66 | cIv, 67 | [data bytes], 68 | [data length], 69 | buffer, 70 | bufferSize, 71 | &encryptedSize); 72 | if (cryptStatus == kCCSuccess) { 73 | result = [NSData dataWithBytesNoCopy:buffer length:encryptedSize]; 74 | } else { 75 | free(buffer); 76 | NSLog(@"[ERROR] failed to encrypt|CCCryptoStatus: %d", cryptStatus); 77 | } 78 | 79 | return result; 80 | } 81 | 82 | + (NSData*)decryptData:(NSData*)data key:(NSData*)key iv:(NSData*)iv; 83 | { 84 | NSData* result = nil; 85 | 86 | // setup key 87 | unsigned char cKey[FBENCRYPT_KEY_SIZE]; 88 | bzero(cKey, sizeof(cKey)); 89 | [key getBytes:cKey length:FBENCRYPT_KEY_SIZE]; 90 | 91 | // setup iv 92 | char cIv[FBENCRYPT_BLOCK_SIZE]; 93 | bzero(cIv, FBENCRYPT_BLOCK_SIZE); 94 | if (iv) { 95 | [iv getBytes:cIv length:FBENCRYPT_BLOCK_SIZE]; 96 | } 97 | 98 | // setup output buffer 99 | size_t bufferSize = [data length] + FBENCRYPT_BLOCK_SIZE; 100 | void *buffer = malloc(bufferSize); 101 | 102 | // do decrypt 103 | size_t decryptedSize = 0; 104 | CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, 105 | FBENCRYPT_ALGORITHM, 106 | kCCOptionPKCS7Padding, 107 | cKey, 108 | FBENCRYPT_KEY_SIZE, 109 | cIv, 110 | [data bytes], 111 | [data length], 112 | buffer, 113 | bufferSize, 114 | &decryptedSize); 115 | 116 | if (cryptStatus == kCCSuccess) { 117 | result = [NSData dataWithBytesNoCopy:buffer length:decryptedSize]; 118 | } else { 119 | free(buffer); 120 | NSLog(@"[ERROR] failed to decrypt| CCCryptoStatus: %d", cryptStatus); 121 | } 122 | 123 | return result; 124 | } 125 | 126 | 127 | + (NSString*)encryptBase64String:(NSString*)string keyString:(NSString*)keyString separateLines:(BOOL)separateLines 128 | { 129 | NSData* data = [self encryptData:[string dataUsingEncoding:NSUTF8StringEncoding] 130 | key:[keyString dataUsingEncoding:NSUTF8StringEncoding] 131 | iv:nil]; 132 | return [data base64EncodedStringWithSeparateLines:separateLines]; 133 | } 134 | 135 | + (NSString*)decryptBase64String:(NSString*)encryptedBase64String keyString:(NSString*)keyString 136 | { 137 | NSData* encryptedData = [NSData dataFromBase64String:encryptedBase64String]; 138 | NSData* data = [self decryptData:encryptedData 139 | key:[keyString dataUsingEncoding:NSUTF8StringEncoding] 140 | iv:nil]; 141 | if (data) { 142 | return [[[NSString alloc] initWithData:data 143 | encoding:NSUTF8StringEncoding] autorelease]; 144 | } else { 145 | return nil; 146 | } 147 | } 148 | 149 | 150 | #define FBENCRYPT_IV_HEX_LEGNTH (FBENCRYPT_BLOCK_SIZE*2) 151 | 152 | + (NSData*)generateIv 153 | { 154 | static dispatch_once_t onceToken; 155 | dispatch_once(&onceToken, ^{ 156 | srand(time(NULL)); 157 | }); 158 | 159 | char cIv[FBENCRYPT_BLOCK_SIZE]; 160 | for (int i=0; i < FBENCRYPT_BLOCK_SIZE; i++) { 161 | cIv[i] = rand() % 256; 162 | } 163 | return [NSData dataWithBytes:cIv length:FBENCRYPT_BLOCK_SIZE]; 164 | } 165 | 166 | 167 | + (NSString*)hexStringForData:(NSData*)data 168 | { 169 | if (data == nil) { 170 | return nil; 171 | } 172 | 173 | NSMutableString* hexString = [NSMutableString string]; 174 | 175 | const unsigned char *p = [data bytes]; 176 | 177 | for (int i=0; i < [data length]; i++) { 178 | [hexString appendFormat:@"%02x", *p++]; 179 | } 180 | return hexString; 181 | } 182 | 183 | + (NSData*)dataForHexString:(NSString*)hexString 184 | { 185 | if (hexString == nil) { 186 | return nil; 187 | } 188 | 189 | const char* ch = [[hexString lowercaseString] cStringUsingEncoding:NSUTF8StringEncoding]; 190 | NSMutableData* data = [NSMutableData data]; 191 | while (*ch) { 192 | char byte = 0; 193 | if ('0' <= *ch && *ch <= '9') { 194 | byte = *ch - '0'; 195 | } else if ('a' <= *ch && *ch <= 'f') { 196 | byte = *ch - 'a' + 10; 197 | } 198 | ch++; 199 | byte = byte << 4; 200 | if (*ch) { 201 | if ('0' <= *ch && *ch <= '9') { 202 | byte += *ch - '0'; 203 | } else if ('a' <= *ch && *ch <= 'f') { 204 | byte += *ch - 'a' + 10; 205 | } 206 | ch++; 207 | } 208 | [data appendBytes:&byte length:1]; 209 | } 210 | return data; 211 | } 212 | 213 | @end 214 | -------------------------------------------------------------------------------- /NSData+Base64.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Base64.h 3 | // base64 4 | // 5 | // Created by Matt Gallagher on 2009/06/03. 6 | // Copyright 2009 Matt Gallagher. All rights reserved. 7 | // 8 | // This software is provided 'as-is', without any express or implied 9 | // warranty. In no event will the authors be held liable for any damages 10 | // arising from the use of this software. Permission is granted to anyone to 11 | // use this software for any purpose, including commercial applications, and to 12 | // alter it and redistribute it freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would be 17 | // appreciated but is not required. 18 | // 2. Altered source versions must be plainly marked as such, and must not be 19 | // misrepresented as being the original software. 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | #import 25 | 26 | void *NewBase64Decode( 27 | const char *inputBuffer, 28 | size_t length, 29 | size_t *outputLength); 30 | 31 | char *NewBase64Encode( 32 | const void *inputBuffer, 33 | size_t length, 34 | bool separateLines, 35 | size_t *outputLength); 36 | 37 | @interface NSData (Base64) 38 | 39 | + (NSData *)dataFromBase64String:(NSString *)aString; 40 | - (NSString *)base64EncodedString; 41 | 42 | // added by Hiroshi Hashiguchi 43 | - (NSString *)base64EncodedStringWithSeparateLines:(BOOL)separateLines; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /NSData+Base64.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Base64.m 3 | // base64 4 | // 5 | // Created by Matt Gallagher on 2009/06/03. 6 | // Copyright 2009 Matt Gallagher. All rights reserved. 7 | // 8 | // This software is provided 'as-is', without any express or implied 9 | // warranty. In no event will the authors be held liable for any damages 10 | // arising from the use of this software. Permission is granted to anyone to 11 | // use this software for any purpose, including commercial applications, and to 12 | // alter it and redistribute it freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would be 17 | // appreciated but is not required. 18 | // 2. Altered source versions must be plainly marked as such, and must not be 19 | // misrepresented as being the original software. 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | #import "NSData+Base64.h" 25 | 26 | // 27 | // Mapping from 6 bit pattern to ASCII character. 28 | // 29 | static unsigned char base64EncodeLookup[65] = 30 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 31 | 32 | // 33 | // Definition for "masked-out" areas of the base64DecodeLookup mapping 34 | // 35 | #define xx 65 36 | 37 | // 38 | // Mapping from ASCII character to 6 bit pattern. 39 | // 40 | static unsigned char base64DecodeLookup[256] = 41 | { 42 | xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 43 | xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 44 | xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 62, xx, xx, xx, 63, 45 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, xx, xx, xx, xx, xx, xx, 46 | xx, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 47 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, xx, xx, xx, xx, xx, 48 | xx, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 49 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, xx, xx, xx, xx, xx, 50 | xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 51 | xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 52 | xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 53 | xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 54 | xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 55 | xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 56 | xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 57 | xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 58 | }; 59 | 60 | // 61 | // Fundamental sizes of the binary and base64 encode/decode units in bytes 62 | // 63 | #define BINARY_UNIT_SIZE 3 64 | #define BASE64_UNIT_SIZE 4 65 | 66 | // 67 | // NewBase64Decode 68 | // 69 | // Decodes the base64 ASCII string in the inputBuffer to a newly malloced 70 | // output buffer. 71 | // 72 | // inputBuffer - the source ASCII string for the decode 73 | // length - the length of the string or -1 (to specify strlen should be used) 74 | // outputLength - if not-NULL, on output will contain the decoded length 75 | // 76 | // returns the decoded buffer. Must be free'd by caller. Length is given by 77 | // outputLength. 78 | // 79 | void *NewBase64Decode( 80 | const char *inputBuffer, 81 | size_t length, 82 | size_t *outputLength) 83 | { 84 | if (length == -1) 85 | { 86 | length = strlen(inputBuffer); 87 | } 88 | 89 | size_t outputBufferSize = 90 | ((length+BASE64_UNIT_SIZE-1) / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE; 91 | unsigned char *outputBuffer = (unsigned char *)malloc(outputBufferSize); 92 | 93 | size_t i = 0; 94 | size_t j = 0; 95 | while (i < length) 96 | { 97 | // 98 | // Accumulate 4 valid characters (ignore everything else) 99 | // 100 | unsigned char accumulated[BASE64_UNIT_SIZE]; 101 | size_t accumulateIndex = 0; 102 | while (i < length) 103 | { 104 | unsigned char decode = base64DecodeLookup[inputBuffer[i++]]; 105 | if (decode != xx) 106 | { 107 | accumulated[accumulateIndex] = decode; 108 | accumulateIndex++; 109 | 110 | if (accumulateIndex == BASE64_UNIT_SIZE) 111 | { 112 | break; 113 | } 114 | } 115 | } 116 | 117 | // 118 | // Store the 6 bits from each of the 4 characters as 3 bytes 119 | // 120 | // (Uses improved bounds checking suggested by Alexandre Colucci) 121 | // 122 | if(accumulateIndex >= 2) 123 | outputBuffer[j] = (accumulated[0] << 2) | (accumulated[1] >> 4); 124 | if(accumulateIndex >= 3) 125 | outputBuffer[j + 1] = (accumulated[1] << 4) | (accumulated[2] >> 2); 126 | if(accumulateIndex >= 4) 127 | outputBuffer[j + 2] = (accumulated[2] << 6) | accumulated[3]; 128 | j += accumulateIndex - 1; 129 | } 130 | 131 | if (outputLength) 132 | { 133 | *outputLength = j; 134 | } 135 | return outputBuffer; 136 | } 137 | 138 | // 139 | // NewBase64Encode 140 | // 141 | // Encodes the arbitrary data in the inputBuffer as base64 into a newly malloced 142 | // output buffer. 143 | // 144 | // inputBuffer - the source data for the encode 145 | // length - the length of the input in bytes 146 | // separateLines - if zero, no CR/LF characters will be added. Otherwise 147 | // a CR/LF pair will be added every 64 encoded chars. 148 | // outputLength - if not-NULL, on output will contain the encoded length 149 | // (not including terminating 0 char) 150 | // 151 | // returns the encoded buffer. Must be free'd by caller. Length is given by 152 | // outputLength. 153 | // 154 | char *NewBase64Encode( 155 | const void *buffer, 156 | size_t length, 157 | bool separateLines, 158 | size_t *outputLength) 159 | { 160 | const unsigned char *inputBuffer = (const unsigned char *)buffer; 161 | 162 | #define MAX_NUM_PADDING_CHARS 2 163 | #define OUTPUT_LINE_LENGTH 64 164 | #define INPUT_LINE_LENGTH ((OUTPUT_LINE_LENGTH / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE) 165 | #define CR_LF_SIZE 2 166 | 167 | // 168 | // Byte accurate calculation of final buffer size 169 | // 170 | size_t outputBufferSize = 171 | ((length / BINARY_UNIT_SIZE) 172 | + ((length % BINARY_UNIT_SIZE) ? 1 : 0)) 173 | * BASE64_UNIT_SIZE; 174 | if (separateLines) 175 | { 176 | outputBufferSize += 177 | (outputBufferSize / OUTPUT_LINE_LENGTH) * CR_LF_SIZE; 178 | } 179 | 180 | // 181 | // Include space for a terminating zero 182 | // 183 | outputBufferSize += 1; 184 | 185 | // 186 | // Allocate the output buffer 187 | // 188 | char *outputBuffer = (char *)malloc(outputBufferSize); 189 | if (!outputBuffer) 190 | { 191 | return NULL; 192 | } 193 | 194 | size_t i = 0; 195 | size_t j = 0; 196 | const size_t lineLength = separateLines ? INPUT_LINE_LENGTH : length; 197 | size_t lineEnd = lineLength; 198 | 199 | while (true) 200 | { 201 | if (lineEnd > length) 202 | { 203 | lineEnd = length; 204 | } 205 | 206 | for (; i + BINARY_UNIT_SIZE - 1 < lineEnd; i += BINARY_UNIT_SIZE) 207 | { 208 | // 209 | // Inner loop: turn 48 bytes into 64 base64 characters 210 | // 211 | outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2]; 212 | outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i] & 0x03) << 4) 213 | | ((inputBuffer[i + 1] & 0xF0) >> 4)]; 214 | outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i + 1] & 0x0F) << 2) 215 | | ((inputBuffer[i + 2] & 0xC0) >> 6)]; 216 | outputBuffer[j++] = base64EncodeLookup[inputBuffer[i + 2] & 0x3F]; 217 | } 218 | 219 | if (lineEnd == length) 220 | { 221 | break; 222 | } 223 | 224 | // 225 | // Add the newline 226 | // 227 | outputBuffer[j++] = '\r'; 228 | outputBuffer[j++] = '\n'; 229 | lineEnd += lineLength; 230 | } 231 | 232 | if (i + 1 < length) 233 | { 234 | // 235 | // Handle the single '=' case 236 | // 237 | outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2]; 238 | outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i] & 0x03) << 4) 239 | | ((inputBuffer[i + 1] & 0xF0) >> 4)]; 240 | outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i + 1] & 0x0F) << 2]; 241 | outputBuffer[j++] = '='; 242 | } 243 | else if (i < length) 244 | { 245 | // 246 | // Handle the double '=' case 247 | // 248 | outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2]; 249 | outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0x03) << 4]; 250 | outputBuffer[j++] = '='; 251 | outputBuffer[j++] = '='; 252 | } 253 | outputBuffer[j] = 0; 254 | 255 | // 256 | // Set the output length and return the buffer 257 | // 258 | if (outputLength) 259 | { 260 | *outputLength = j; 261 | } 262 | return outputBuffer; 263 | } 264 | 265 | @implementation NSData (Base64) 266 | 267 | // 268 | // dataFromBase64String: 269 | // 270 | // Creates an NSData object containing the base64 decoded representation of 271 | // the base64 string 'aString' 272 | // 273 | // Parameters: 274 | // aString - the base64 string to decode 275 | // 276 | // returns the autoreleased NSData representation of the base64 string 277 | // 278 | + (NSData *)dataFromBase64String:(NSString *)aString 279 | { 280 | NSData *data = [aString dataUsingEncoding:NSASCIIStringEncoding]; 281 | size_t outputLength; 282 | void *outputBuffer = NewBase64Decode([data bytes], [data length], &outputLength); 283 | NSData *result = [NSData dataWithBytes:outputBuffer length:outputLength]; 284 | free(outputBuffer); 285 | return result; 286 | } 287 | 288 | // 289 | // base64EncodedString 290 | // 291 | // Creates an NSString object that contains the base 64 encoding of the 292 | // receiver's data. Lines are broken at 64 characters long. 293 | // 294 | // returns an autoreleased NSString being the base 64 representation of the 295 | // receiver. 296 | // 297 | - (NSString *)base64EncodedString 298 | { 299 | size_t outputLength; 300 | char *outputBuffer = 301 | NewBase64Encode([self bytes], [self length], true, &outputLength); 302 | 303 | NSString *result = 304 | [[[NSString alloc] 305 | initWithBytes:outputBuffer 306 | length:outputLength 307 | encoding:NSASCIIStringEncoding] 308 | autorelease]; 309 | free(outputBuffer); 310 | return result; 311 | } 312 | 313 | // added by Hiroshi Hashiguchi 314 | - (NSString *)base64EncodedStringWithSeparateLines:(BOOL)separateLines 315 | { 316 | size_t outputLength; 317 | char *outputBuffer = 318 | NewBase64Encode([self bytes], [self length], separateLines, &outputLength); 319 | 320 | NSString *result = 321 | [[[NSString alloc] 322 | initWithBytes:outputBuffer 323 | length:outputLength 324 | encoding:NSASCIIStringEncoding] 325 | autorelease]; 326 | free(outputBuffer); 327 | return result; 328 | } 329 | 330 | 331 | @end 332 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CCCrypt wrapper class 2 | ============================= 3 | 4 | FBEncryptor is enabled to encrypt/decrypt a message. Supported encryption algorithm is AES 256 bit only. Additionally BASE64 encode/decode is supported. 5 | 6 | 7 | Usage 8 | ----- 9 | 10 | (1) Encrypt/decrypt plain text message with Base64 encoding 11 | 12 | Encrypt) 13 | 14 | NSString* encrypted = [FBEncryptorAES encryptBase64String:@"Hello" 15 | keyString:@"somekey" 16 | separateLines:NO]; 17 | 18 | The output string is encoded with Base64. 19 | 20 | example) 21 | message: @"Hello" 22 | output : @"gT2IUF9Jzmn7wglXk3XC3w==" 23 | 24 | if 'separateLines:' is NO, no CR/LF characters will be added. 25 | Otherwise a CR/LF pair will be added every 64 encoded chars. 26 | 27 | 28 | Decrypt) 29 | 30 | NSString* decrypted = [FBEncryptorAES decryptBase64String:encrypted 31 | keyString:key]; 32 | 33 | 34 | 35 | (2) Encrypt/decrypt binary data 36 | 37 | NSData* encryptedData = [FBEncryptorAES encryptData:data 38 | keyData:key 39 | iv:iv]; 40 | 41 | NSData* decryptedData = [FBEncryptorAES decryptData:encryptData 42 | keyData:key 43 | iv:iv]; 44 | 45 | The iv is called 'initailization vector' for CBC mode. it is abled to be set nil. 46 | 47 | 48 | (3) Generate iv 49 | 50 | NSData* iv = [FBEncryptorAES generateIv]; 51 | 52 | It generates a 16 bytes random binary value. You can use this value for +encryptData:keyData:iv:. 53 | 54 | 55 | (4) Utiities 56 | 57 | NSData* iv = [FBEncryptorAES generateIv]; 58 | NSString* hexString = [FBEncryptorAES hexStringForData:iv]; 59 | 60 | example: @"b20cd8d972e65762824cc3190040388c" 61 | 62 | NSData* bin = [FBEncryptorAES dataForHexString:hexString]; 63 | 64 | 65 | 66 | Features 67 | -------- 68 | - Only support AES256/CBC/PKCS7padding 69 | - Base64 encoding is suported 70 | 71 | 72 | Customize 73 | --------- 74 | 75 | It is able to change below constants: 76 | 77 | FBEncryptor.h 78 | #define FBENCRYPT_KEY_SIZE kCCKeySizeAES256 79 | 80 | If you want to use AES 128 bit key, you can set the constant like below: 81 | 82 | #define FBENCRYPT_KEY_SIZE kCCKeySizeAES128 83 | 84 | NOTE: If you change the constant, the testcase will be failed (it is made for AES 256 bit key). 85 | 86 | 87 | Installation 88 | ----------- 89 | 90 | You should copy below files to your projects. 91 | 92 | FBEncryptor.h 93 | FBEncryptor.m 94 | NSData+Base64.h 95 | NSData+Base64.m 96 | 97 | 98 | Etc 99 | ------- 100 | Special thanks for Matt Gallagher (author of NSData+Base64 code). 101 | 102 | "Cocoa with Love: Base64 encoding options on the Mac and iPhone" 103 | http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html 104 | 105 | 106 | License 107 | ------- 108 | (1) FBEncryptorAES.m/FBEncryptorAES.h 109 | 110 | MIT 111 | 112 | Copyright (c) 2011 Hiroshi Hashiguchi 113 | 114 | Permission is hereby granted, free of charge, to any person obtaining a copy 115 | of this software and associated documentation files (the "Software"), to deal 116 | in the Software without restriction, including without limitation the rights 117 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 118 | copies of the Software, and to permit persons to whom the Software is 119 | furnished to do so, subject to the following conditions: 120 | 121 | The above copyright notice and this permission notice shall be included in 122 | all copies or substantial portions of the Software. 123 | 124 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 125 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 126 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 127 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 128 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 129 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 130 | THE SOFTWARE. 131 | 132 | 133 | 134 | (2) NSData+Base64.m/NSData+Base64.h 135 | 136 | Created by Matt Gallagher on 2009/06/03. 137 | Copyright 2009 Matt Gallagher. All rights reserved. 138 | 139 | This software is provided 'as-is', without any express or implied 140 | warranty. In no event will the authors be held liable for any damages 141 | arising from the use of this software. Permission is granted to anyone to 142 | use this software for any purpose, including commercial applications, and to 143 | alter it and redistribute it freely, subject to the following restrictions: 144 | 145 | 1. The origin of this software must not be misrepresented; you must not 146 | claim that you wrote the original software. If you use this software 147 | in a product, an acknowledgment in the product documentation would be 148 | appreciated but is not required. 149 | 2. Altered source versions must be plainly marked as such, and must not be 150 | misrepresented as being the original software. 151 | 3. This notice may not be removed or altered from any source 152 | distribution. 153 | 154 | 155 | --------------------------------------------------------------------------------